foundation and basic use maven

Introduction maven

Maven is based on a project object model (POM project object model) to achieve, you can build information (configuration) to manage the project by a short description, software project management tool reports and documents. 
  Specific role: 
    project encountered compile, test, operation, package, deploy a series of operations more complicated. 
    Between jar (jar manually manage package dependencies) jar package conflicts, version adaptation. (Jar file to resolve dependencies) 
    If the level of ten million project. The Project (Business complex) split sub (easy to control and manage the development process). 
    Automated deployment (convenient deployment process)

maven installation and configuration

1   Download 
    URL: HTTP: // maven.apache.org/   // .zip version 
2   installation 
    decompression: the Apache -maven-3.5.4- bin.zip
 3   Configuration 
    to configure the system environment variables MAVEN_HOME 
    configure the system environment variable path
 4   test 
    cmd > mvn - V
 . 5   configure a local repository 
        configuration file: % MAVEN_HOME% / the conf / the settings.xml 
        configure the local repository: <localRepository> local Storage path </ localRepository> 
. 6   arranged JDK
      <profile>     
        <ID> jdk18 </ ID>     
        <Activation>     
            <activeByDefault> to true</activeByDefault>    
            <jdk>1.8</jdk>    
        </activation>    
        <properties>    
            <maven.compiler.source>1.8</maven.compiler.source>    
            <maven.compiler.target>1.8</maven.compiler.target>    
            <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>    
        </properties>     
    </profile>  
7  配置中央库
  <mirrors>
        <mirror>
        <id>nexus-aliyun</id>
        <mirrorOf>*</mirrorOf>
        <name>Nexus aliyun</name>
        <url>http://maven.aliyun.com/nexus/content/groups/public</url>
      </mirror> 
  </mirrors>

 maven Getting Started

Create a java project 
    mvn archetype: the Generate -DgroupId com.offcn.maven.quickstart-DartifactId = = = DarchetypeArtifactId the Simple Maven-archetype- QuickStart 
Maven java project structure 
    pom.xml core configuration, the project root 
    src / main / java java source code directory 
    the src / main / Resources Java profile directory (hereinafter maven project profiles are put here) 
    the src / test / Java source directory test 
    the src / test / Resources test configuration directory 
    target output directory (byte code files and package jar) 
commonly used maven command 
   mvn clean production project to clean up temporary files, usually target directory module 
  mvn compile source code is compiled, src module compiled under the general / main / the Java directory
  mvn Package Penalty for     project packaging tools, such as jar or war will generate a file in the target directory module 
  mvn test test command, or execute src / the Test / the Java / test case under the junit. 
  mvn install the packaged jar / copy the files to your war local warehouse, for use by other modules 
to create a maven web project 
    mvn archetype: the Generate -DgroupId com.offcn.maven.quickstart-DartifactId = = = myWebApp DarchetypeArtifactId-Maven archetype-the webapp -Dversion = 0.0.1- Snapshot 
maven web project structure 
  pom.xml core configuration 
  src / main / the Java the Java source code 
  src / main / Resources the Java configuration 
  src / main / the webapp project in the Eclipse Web directory WebContent
     | - WEB- INF
        | - the web.xml 
  src / the Test test 
  target output directory 

by mvn tomcat7: run run 
    modify pom.xml file:
    <Build> 
      <finalName> myWebApp </ finalName> 
      <- Configuration tomcat plug-in, web-side -!> 
      < plugins> 
            <plugin> 
                <the groupId> org.apache.tomcat.maven </ the groupId> 
                <the artifactId> tomcat7-Maven-plugin </ the artifactId> 
                <Configuration> 
                    <path> / App </ path> 
                    <Port> 8080 </ Port > 
                </ Configuration> 
            </ plugin>
       </plugins>
    </build>

eclipse maven integration 

1 .eclipse configured in position
 2 . Cancellation index Download
 Configuration Maven 
4. Browse local warehouse, rewrite build an index

 

Create a maven project in eclipse

Step 1: Select "maven project", if no new right, other obtained by 
Step 2: Select the project location, change the default 
Step 3: Select backbone 
Step Four: Parameter Setting items 
Step Five: The Navigator view, directly in the src / main java build directory folder directory, etc.

Project Cohesion

Companies to develop the most commonly used
     1 . Establishing a parent project, packaged the way for the pom, version management jar package, the project all works in his father's engineering
     2 . Create a module maven, named jd_common, generic tools
     3 . Create a module maven, Engineering services layer, POM Engineering, Engineering polymerization
     5 Create module maven, dao layer, jar package
     6 Create module maven, service layer, jar package
     7. Create Maven Module1, interface , jar package
     8 Create module maven, servlet layer, jar package
     9 . create a module maven, web layer, war package 

to call other projects need to introduce rely, rely on the name change, calling other jar package needs to be positioned on search sites, then the introduction of dependence

Guess you like

Origin www.cnblogs.com/lovemeng1314/p/11494948.html