2.3. maven

简介:

2.3.1. 安装

2.3.1.1. Ubuntu

$ sudo apt-get install maven2

$ mvn -version
Apache Maven 2.2.1 (rdebian-4)
Java version: 1.6.0_22
Java home: /usr/lib/jvm/java-6-openjdk/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux" version: "2.6.38-8-generic" arch: "amd64" Family: "unix"

			
JAVA_HOME="/usr/lib/jvm/java-6-openjdk/jre"
MAVEN_HOME="/usr/share/maven2/"
			

2.3.1.2. 源码安装

curl -s https://raw.githubusercontent.com/oscm/shell/master/lang/java/maven/maven.sh | bash
			

2.3.2. Maven 命令

2.3.2.1. help

查看可用的pom定义

mvn help:effective-pom			
		

2.3.2.2. archetype:create

创建 Maven 项目

			
mvn archetype:create   -DarchetypeGroupId=org.apache.maven.archetypes   -DgroupId=com.company -DartifactId=my-app			
			
			
			
mvn archetype:create 
    -DgroupId=packageName    
    -DartifactId=webappName 
    -DarchetypeArtifactId=maven-archetype-webapp 			
			
			

2.3.2.3. clean

清楚

$ mvn clean		
			

2.3.2.4. compile

编译项目的源代码

$ mvn compile
			

2.3.2.5. test

编译测试的源代码

mvn test-compile			
			

运行测试

$ mvn test
			
			

打包但不测试

			
mvn -D maven.test.skip=true package
			
			

2.3.2.6. package

将编译后的代码打包

$ mvn package
			
$ ls target/*.war
target/www.netkiller.cn-0.0.1-SNAPSHOT.war
			

2.3.2.7. install

将项目打包后安装到本地仓库,可以作为其它项目的本地依赖。

$ mvn install		
			

跳过测试

mvn install -Dmaven.test.skip=true			
			
2.3.2.7.1. install-file

安装本地jar文件到Maven的.m2库中。

				
mvn install:install-file -Dfile=Path/to/your.jar} -DgroupId=com.example -DartifactId=project -Dversion=1.2.0 -Dpackaging=jar
				
				

2.3.2.8. war

mvn compile war:war			
			
mvn compile war:exploded			
			
mvn compile war:inplace
			

2.3.2.9. exec

$ mvn exec:java -Dexec.mainClass="cn.netkiller.Test"			
			

2.3.2.10. dependency

2.3.2.10.1. build-classpath
$ mvn dependency:build-classpath
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building api.netkiller.cn 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-dependency-plugin:2.10:build-classpath (default-cli) @ api.cf88.com ---
[INFO] Dependencies classpath:
/www/.m2/repository/org/springframework/boot/spring-boot-starter-web/1.3.0.RELEASE/spring-boot-starter-web-1.3.0.RELEASE.jar:......:/www/.m2/repository/junit/junit/4.12/junit-4.12.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.692 s
[INFO] Finished at: 2016-08-10T17:32:49+08:00
[INFO] Final Memory: 25M/162M
[INFO] ------------------------------------------------------------------------
			
			
2.3.2.10.2. dependency:tree 显示包依赖树
[www@iZ62yln3rjjZ repository]$ mvn dependency:tree
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building api.example.com 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-dependency-plugin:2.10:tree (default-cli) @ api.cf88.com ---
[INFO] cf88.com:api.cf88.com:jar:0.0.1-SNAPSHOT
[INFO] +- org.springframework.boot:spring-boot-starter-web:jar:1.3.0.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter:jar:1.3.0.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-starter-logging:jar:1.3.0.RELEASE:compile
[INFO] |  |  |  +- ch.qos.logback:logback-classic:jar:1.1.3:compile
[INFO] |  |  |  |  \- ch.qos.logback:logback-core:jar:1.1.3:compile
[INFO] |  |  |  +- org.slf4j:jul-to-slf4j:jar:1.7.13:compile
[INFO] |  |  |  \- org.slf4j:log4j-over-slf4j:jar:1.7.13:compile
[INFO] |  |  \- org.yaml:snakeyaml:jar:1.16:runtime
[INFO] |  +- org.springframework.boot:spring-boot-starter-tomcat:jar:1.3.0.RELEASE:compile
[INFO] |  |  +- org.apache.tomcat.embed:tomcat-embed-core:jar:8.0.28:compile
[INFO] |  |  +- org.apache.tomcat.embed:tomcat-embed-el:jar:8.0.28:compile
[INFO] |  |  +- org.apache.tomcat.embed:tomcat-embed-logging-juli:jar:8.0.28:compile
[INFO] |  |  \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:8.0.28:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-validation:jar:1.3.0.RELEASE:compile
[INFO] |  |  \- org.hibernate:hibernate-validator:jar:5.2.2.Final:compile
[INFO] |  |     +- javax.validation:validation-api:jar:1.1.0.Final:compile
[INFO] |  |     \- com.fasterxml:classmate:jar:1.1.0:compile
[INFO] |  +- com.fasterxml.jackson.core:jackson-databind:jar:2.6.3:compile
[INFO] |  |  +- com.fasterxml.jackson.core:jackson-annotations:jar:2.6.3:compile
[INFO] |  |  \- com.fasterxml.jackson.core:jackson-core:jar:2.6.3:compile
[INFO] |  +- org.springframework:spring-web:jar:4.2.3.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-aop:jar:4.2.3.RELEASE:compile
[INFO] |  |     \- aopalliance:aopalliance:jar:1.0:compile
[INFO] |  \- org.springframework:spring-webmvc:jar:4.2.3.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-data-jpa:jar:1.3.0.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-aop:jar:1.3.0.RELEASE:compile
[INFO] |  |  \- org.aspectj:aspectjweaver:jar:1.8.7:compile
[INFO] |  +- org.hibernate:hibernate-entitymanager:jar:4.3.11.Final:compile
[INFO] |  |  +- org.jboss.logging:jboss-logging:jar:3.3.0.Final:compile
[INFO] |  |  +- org.jboss.logging:jboss-logging-annotations:jar:1.2.0.Beta1:compile
[INFO] |  |  +- org.hibernate:hibernate-core:jar:4.3.11.Final:compile
[INFO] |  |  |  +- antlr:antlr:jar:2.7.7:compile
[INFO] |  |  |  \- org.jboss:jandex:jar:1.1.0.Final:compile
[INFO] |  |  +- dom4j:dom4j:jar:1.6.1:compile
[INFO] |  |  |  \- xml-apis:xml-apis:jar:1.0.b2:compile
[INFO] |  |  +- org.hibernate.common:hibernate-commons-annotations:jar:4.0.5.Final:compile
[INFO] |  |  +- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:jar:1.0.0.Final:compile
[INFO] |  |  \- org.javassist:javassist:jar:3.18.1-GA:compile
[INFO] |  +- javax.transaction:javax.transaction-api:jar:1.2:compile
[INFO] |  +- org.springframework.data:spring-data-jpa:jar:1.9.1.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-orm:jar:4.2.3.RELEASE:compile
[INFO] |  \- org.springframework:spring-aspects:jar:4.2.3.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-jdbc:jar:1.3.0.RELEASE:compile
[INFO] |  +- org.apache.tomcat:tomcat-jdbc:jar:8.0.28:compile
[INFO] |  |  \- org.apache.tomcat:tomcat-juli:jar:8.0.28:compile
[INFO] |  \- org.springframework:spring-jdbc:jar:4.2.3.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-redis:jar:1.3.0.RELEASE:compile
[INFO] |  +- org.springframework.data:spring-data-redis:jar:1.6.1.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-context-support:jar:4.2.3.RELEASE:compile
[INFO] |  \- redis.clients:jedis:jar:2.7.3:compile
[INFO] |     \- org.apache.commons:commons-pool2:jar:2.4.2:compile
[INFO] +- org.springframework.boot:spring-boot-starter-data-mongodb:jar:1.3.0.RELEASE:compile
[INFO] |  \- org.mongodb:mongo-java-driver:jar:2.13.3:compile
[INFO] +- org.springframework.boot:spring-boot-starter-amqp:jar:1.3.0.RELEASE:compile
[INFO] |  +- org.springframework:spring-messaging:jar:4.2.3.RELEASE:compile
[INFO] |  \- org.springframework.amqp:spring-rabbit:jar:1.5.2.RELEASE:compile
[INFO] |     +- org.springframework.retry:spring-retry:jar:1.1.2.RELEASE:compile
[INFO] |     +- org.springframework.amqp:spring-amqp:jar:1.5.2.RELEASE:compile
[INFO] |     +- com.rabbitmq:http-client:jar:1.0.0.RELEASE:compile
[INFO] |     |  \- org.apache.httpcomponents:httpclient:jar:4.5.1:compile
[INFO] |     |     +- org.apache.httpcomponents:httpcore:jar:4.4.4:compile
[INFO] |     |     \- commons-codec:commons-codec:jar:1.9:compile
[INFO] |     \- com.rabbitmq:amqp-client:jar:3.5.6:compile
[INFO] +- org.springframework.boot:spring-boot-devtools:jar:1.3.0.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot:jar:1.3.0.RELEASE:compile
[INFO] |  \- org.springframework.boot:spring-boot-autoconfigure:jar:1.3.0.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-test:jar:1.3.0.RELEASE:test
[INFO] |  +- org.mockito:mockito-core:jar:1.10.19:test
[INFO] |  |  \- org.objenesis:objenesis:jar:2.1:test
[INFO] |  +- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] |  +- org.hamcrest:hamcrest-library:jar:1.3:test
[INFO] |  +- org.springframework:spring-core:jar:4.2.3.RELEASE:compile
[INFO] |  \- org.springframework:spring-test:jar:4.2.3.RELEASE:test
[INFO] +- org.springframework.data:spring-data-mongodb:jar:1.8.1.RELEASE:compile
[INFO] |  +- org.springframework:spring-tx:jar:4.2.3.RELEASE:compile
[INFO] |  +- org.springframework:spring-context:jar:4.2.3.RELEASE:compile
[INFO] |  +- org.springframework:spring-beans:jar:4.2.3.RELEASE:compile
[INFO] |  +- org.springframework:spring-expression:jar:4.2.3.RELEASE:compile
[INFO] |  +- org.springframework.data:spring-data-commons:jar:1.11.1.RELEASE:compile
[INFO] |  +- org.slf4j:slf4j-api:jar:1.7.13:compile
[INFO] |  \- org.slf4j:jcl-over-slf4j:jar:1.7.13:compile
[INFO] +- mysql:mysql-connector-java:jar:5.1.37:compile
[INFO] +- com.google.code.gson:gson:jar:2.3.1:compile
[INFO] \- junit:junit:jar:4.12:test
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.400 s
[INFO] Finished at: 2016-08-09T10:25:07+08:00
[INFO] Final Memory: 23M/163M
[INFO] ------------------------------------------------------------------------		
			
2.3.2.10.3. copy-dependencies 导出依赖包
$ mvn dependency:copy-dependencies
			
$ ls target/dependency/
antlr-2.7.7.jar                                javassist-3.18.1-GA.jar                    snakeyaml-1.16.jar                                spring-boot-starter-web-1.3.0.RELEASE.jar        spring-webmvc-4.2.3.RELEASE.jar
aopalliance-1.0.jar                            javax.transaction-api-1.2.jar              spring-aop-4.2.3.RELEASE.jar                      spring-boot-starter-websocket-1.3.0.RELEASE.jar  spring-websocket-4.2.3.RELEASE.jar
aspectjweaver-1.8.7.jar                        jboss-logging-3.3.0.Final.jar              spring-aspects-4.2.3.RELEASE.jar                  spring-context-4.2.3.RELEASE.jar                 thymeleaf-2.1.4.RELEASE.jar
classmate-1.1.0.jar                            jboss-logging-annotations-1.2.0.Beta1.jar  spring-beans-4.2.3.RELEASE.jar                    spring-core-4.2.3.RELEASE.jar                    thymeleaf-layout-dialect-1.3.1.jar
dom4j-1.6.1.jar                                jcl-over-slf4j-1.7.13.jar                  spring-boot-1.3.0.RELEASE.jar                     spring-data-commons-1.11.1.RELEASE.jar           thymeleaf-spring4-2.1.4.RELEASE.jar
groovy-2.4.4.jar                               jstl-1.2.jar                               spring-boot-autoconfigure-1.3.0.RELEASE.jar       spring-data-jpa-1.9.1.RELEASE.jar                tomcat-embed-core-8.0.28.jar
hibernate-commons-annotations-4.0.5.Final.jar  jul-to-slf4j-1.7.13.jar                    spring-boot-starter-1.3.0.RELEASE.jar             spring-expression-4.2.3.RELEASE.jar              tomcat-embed-el-8.0.28.jar
hibernate-core-4.3.11.Final.jar                log4j-over-slf4j-1.7.13.jar                spring-boot-starter-aop-1.3.0.RELEASE.jar         spring-jdbc-4.2.3.RELEASE.jar                    tomcat-embed-logging-juli-8.0.28.jar
hibernate-entitymanager-4.3.11.Final.jar       logback-classic-1.1.3.jar                  spring-boot-starter-data-jpa-1.3.0.RELEASE.jar    spring-messaging-4.2.3.RELEASE.jar               tomcat-embed-websocket-8.0.28.jar
hibernate-jpa-2.1-api-1.0.0.Final.jar          logback-core-1.1.3.jar                     spring-boot-starter-jdbc-1.3.0.RELEASE.jar        spring-orm-4.2.3.RELEASE.jar                     tomcat-jdbc-8.0.28.jar
hibernate-validator-5.2.2.Final.jar            mybatis-3.3.0.jar                          spring-boot-starter-logging-1.3.0.RELEASE.jar     spring-security-config-4.0.3.RELEASE.jar         tomcat-juli-8.0.28.jar
jackson-annotations-2.6.3.jar                  mybatis-spring-1.2.3.jar                   spring-boot-starter-security-1.3.0.RELEASE.jar    spring-security-core-4.0.3.RELEASE.jar           unbescape-1.1.0.RELEASE.jar
jackson-core-2.6.3.jar                         mysql-connector-java-5.1.37.jar            spring-boot-starter-thymeleaf-1.3.0.RELEASE.jar   spring-security-web-4.0.3.RELEASE.jar            validation-api-1.1.0.Final.jar
jackson-databind-2.6.3.jar                     ognl-3.0.8.jar                             spring-boot-starter-tomcat-1.3.0.RELEASE.jar      spring-tx-4.2.3.RELEASE.jar                      xml-apis-1.0.b2.jar
jandex-1.1.0.Final.jar                         slf4j-api-1.7.13.jar                       spring-boot-starter-validation-1.3.0.RELEASE.jar  spring-web-4.2.3.RELEASE.jar		
			
2.3.2.10.4. analyze 查看未被使用的包
$ mvn dependency:analyze			
			
2.3.2.10.5. sources 下载源码
mvn dependency:sources			
			

2.3.2.11. jar

			
mvn -Djar.finalName=myCustomName package			
			
			
			
mvn jar:jar -Djar.finalName=custom-jar-name			
			
			

2.3.2.12. help:describe

显示插件的详细信息

			
MacBook-Pro:deployment neo$ mvn help:describe -DgroupId=org.apache.maven.plugins                   -DartifactId=maven-war-plugin                   -Ddetail=true
[INFO] Scanning for projects...
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-help-plugin:2.2:describe (default-cli) @ standalone-pom ---
[INFO] org.apache.maven.plugins:maven-war-plugin:3.1.0

Name: Apache Maven WAR Plugin
Description: Builds a Web Application Archive (WAR) file from the project
  output and its dependencies.
Group Id: org.apache.maven.plugins
Artifact Id: maven-war-plugin
Version: 3.1.0
Goal Prefix: war

This plugin has 4 goals:

war:exploded
  Description: Create an exploded webapp in a specified directory.
  Implementation: org.apache.maven.plugins.war.WarExplodedMojo
  Language: java
  Bound to phase: package

  Available parameters:

    archive
      The archive configuration to use. See Maven Archiver Reference.

    archiveClasses (Default: false)
      Whether a JAR file will be created for the classes in the webapp. Using
      this optional configuration parameter will make the compiled classes to
      be archived into a JAR file and the classes directory will then be
      excluded from the webapp.

    cacheFile (Default: ${project.build.directory}/war/work/webapp-cache.xml)
      Required: true
      The file containing the webapp structure cache.

    containerConfigXML
      The path to a configuration file for the servlet container. Note that the
      file name may be different for different servlet containers. Apache
      Tomcat uses a configuration file named context.xml. The file will be
      copied to the META-INF directory.

    delimiters
      Set of delimiters for expressions to filter within the resources. These
      delimiters are specified in the form 'beginToken*endToken'. If no '*' is
      given, the delimiter is assumed to be the same for start and end.
      
      So, the default filtering delimiters might be specified as:
      
      <delimiters>
        <delimiter>${*}</delimiter>
        <delimiter>@</delimiter>
      </delimiters>
      
      Since the '@' delimiter is the same on both ends, we don't need to
      specify '@*@' (though we can).

    dependentWarExcludes
      The comma separated list of tokens to exclude when doing a WAR overlay.
      Default is Overlay.DEFAULT_EXCLUDES

    dependentWarIncludes
      The comma separated list of tokens to include when doing a WAR overlay.
      Default is Overlay.DEFAULT_INCLUDES

    escapedBackslashesInFilePath (Default: false)
      To escape interpolated values with Windows path c:\foo\bar will be
      replaced with c:\\foo\\bar.

    escapeString
      Expression preceded with this String won't be interpolated. \${foo} will
      be replaced with ${foo}.

    filteringDeploymentDescriptors (Default: false)
      To filter deployment descriptors. Disabled by default.

    filters
      Filters (property files) to include during the interpolation of the
      pom.xml.

    includeEmptyDirectories (Default: false)
      (no description available)

    nonFilteredFileExtensions
      A list of file extensions that should not be filtered. Will be used when
      filtering webResources and overlays.

    outputFileNameMapping
      The file name mapping to use when copying libraries and TLDs. If no file
      mapping is set (default) the files are copied with their standard names.

    overlays
      The overlays to apply. Each <overlay> element may contain:
      - id (defaults to currentBuild)
      - groupId (if this and artifactId are null, then the current project is
        treated as its own overlay)
      - artifactId (see above)
      - classifier
      - type
      - includes (a list of string patterns)
      - excludes (a list of string patterns)
      - filtered (defaults to false)
      - skip (defaults to false)
      - targetPath (defaults to root of webapp structure)

    recompressZippedFiles (Default: true)
      Indicates if zip archives (jar,zip etc) being added to the war should be
      compressed again. Compressing again can result in smaller archive size,
      but gives noticeably longer execution time.

    resourceEncoding (Default: ${project.build.sourceEncoding})
      The encoding to use when copying filtered web resources.

    supportMultiLineFiltering (Default: false)
      Stop searching endToken at the end of line

    useCache (Default: false)
      Whether the cache should be used to save the status of the webapp across
      multiple runs. Experimental feature so disabled by default.

    useDefaultDelimiters (Default: true)
      Use default delimiters in addition to custom delimiters, if any.

    useJvmChmod (Default: true)
      use jvmChmod rather that cli chmod and forking process

    warSourceDirectory (Default: ${basedir}/src/main/webapp)
      Required: true
      Single directory for extra files to include in the WAR. This is where you
      place your JSP files.

    warSourceExcludes
      The comma separated list of tokens to exclude when copying the content of
      the warSourceDirectory.

    warSourceIncludes (Default: **)
      The comma separated list of tokens to include when copying the content of
      the warSourceDirectory.

    webappDirectory (Default:
    ${project.build.directory}/${project.build.finalName})
      Required: true
      The directory where the webapp is built.

    webResources
      The list of webResources we want to transfer.

    webXml
      The path to the web.xml file to use.

    workDirectory (Default: ${project.build.directory}/war/work)
      Required: true
      Directory to unpack dependent WARs into if needed.

war:help
  Description: Display help information on maven-war-plugin.
    Call mvn war:help -Ddetail=true -Dgoal=<goal-name> to display parameter
    details.
  Implementation: org.apache.maven.plugins.war.HelpMojo
  Language: java

  Available parameters:

    detail (Default: false)
      User property: detail
      If true, display all settable properties for each goal.

    goal
      User property: goal
      The name of the goal for which to show help. If unspecified, all goals
      will be displayed.

    indentSize (Default: 2)
      User property: indentSize
      The number of spaces per indentation level, should be positive.

    lineLength (Default: 80)
      User property: lineLength
      The maximum length of a display line, should be positive.

war:inplace
  Description: Generate the webapp in the WAR source directory.
  Implementation: org.apache.maven.plugins.war.WarInPlaceMojo
  Language: java

  Available parameters:

    archive
      The archive configuration to use. See Maven Archiver Reference.

    archiveClasses (Default: false)
      Whether a JAR file will be created for the classes in the webapp. Using
      this optional configuration parameter will make the compiled classes to
      be archived into a JAR file and the classes directory will then be
      excluded from the webapp.

    cacheFile (Default: ${project.build.directory}/war/work/webapp-cache.xml)
      Required: true
      The file containing the webapp structure cache.

    containerConfigXML
      The path to a configuration file for the servlet container. Note that the
      file name may be different for different servlet containers. Apache
      Tomcat uses a configuration file named context.xml. The file will be
      copied to the META-INF directory.

    delimiters
      Set of delimiters for expressions to filter within the resources. These
      delimiters are specified in the form 'beginToken*endToken'. If no '*' is
      given, the delimiter is assumed to be the same for start and end.
      
      So, the default filtering delimiters might be specified as:
      
      <delimiters>
        <delimiter>${*}</delimiter>
        <delimiter>@</delimiter>
      </delimiters>
      
      Since the '@' delimiter is the same on both ends, we don't need to
      specify '@*@' (though we can).

    dependentWarExcludes
      The comma separated list of tokens to exclude when doing a WAR overlay.
      Default is Overlay.DEFAULT_EXCLUDES

    dependentWarIncludes
      The comma separated list of tokens to include when doing a WAR overlay.
      Default is Overlay.DEFAULT_INCLUDES

    escapedBackslashesInFilePath (Default: false)
      To escape interpolated values with Windows path c:\foo\bar will be
      replaced with c:\\foo\\bar.

    escapeString
      Expression preceded with this String won't be interpolated. \${foo} will
      be replaced with ${foo}.

    filteringDeploymentDescriptors (Default: false)
      To filter deployment descriptors. Disabled by default.

    filters
      Filters (property files) to include during the interpolation of the
      pom.xml.

    includeEmptyDirectories (Default: false)
      (no description available)

    nonFilteredFileExtensions
      A list of file extensions that should not be filtered. Will be used when
      filtering webResources and overlays.

    outputFileNameMapping
      The file name mapping to use when copying libraries and TLDs. If no file
      mapping is set (default) the files are copied with their standard names.

    overlays
      The overlays to apply. Each <overlay> element may contain:
      - id (defaults to currentBuild)
      - groupId (if this and artifactId are null, then the current project is
        treated as its own overlay)
      - artifactId (see above)
      - classifier
      - type
      - includes (a list of string patterns)
      - excludes (a list of string patterns)
      - filtered (defaults to false)
      - skip (defaults to false)
      - targetPath (defaults to root of webapp structure)

    recompressZippedFiles (Default: true)
      Indicates if zip archives (jar,zip etc) being added to the war should be
      compressed again. Compressing again can result in smaller archive size,
      but gives noticeably longer execution time.

    resourceEncoding (Default: ${project.build.sourceEncoding})
      The encoding to use when copying filtered web resources.

    supportMultiLineFiltering (Default: false)
      Stop searching endToken at the end of line

    useCache (Default: false)
      Whether the cache should be used to save the status of the webapp across
      multiple runs. Experimental feature so disabled by default.

    useDefaultDelimiters (Default: true)
      Use default delimiters in addition to custom delimiters, if any.

    useJvmChmod (Default: true)
      use jvmChmod rather that cli chmod and forking process

    warSourceDirectory (Default: ${basedir}/src/main/webapp)
      Required: true
      Single directory for extra files to include in the WAR. This is where you
      place your JSP files.

    warSourceExcludes
      The comma separated list of tokens to exclude when copying the content of
      the warSourceDirectory.

    warSourceIncludes (Default: **)
      The comma separated list of tokens to include when copying the content of
      the warSourceDirectory.

    webappDirectory (Default:
    ${project.build.directory}/${project.build.finalName})
      Required: true
      The directory where the webapp is built.

    webResources
      The list of webResources we want to transfer.

    webXml
      The path to the web.xml file to use.

    workDirectory (Default: ${project.build.directory}/war/work)
      Required: true
      Directory to unpack dependent WARs into if needed.

war:war
  Description: Build a WAR file.
  Implementation: org.apache.maven.plugins.war.WarMojo
  Language: java
  Bound to phase: package

  Available parameters:

    archive
      The archive configuration to use. See Maven Archiver Reference.

    archiveClasses (Default: false)
      Whether a JAR file will be created for the classes in the webapp. Using
      this optional configuration parameter will make the compiled classes to
      be archived into a JAR file and the classes directory will then be
      excluded from the webapp.

    attachClasses (Default: false)
      Whether classes (that is the content of the WEB-INF/classes directory)
      should be attached to the project as an additional artifact.
      By default the classifier for the additional artifact is 'classes'. You
      can change it with the someclassifier parameter.
      
      If this parameter true, another project can depend on the classes by
      writing something like:
      
      
        myGroup
        myArtifact
        myVersion
        classes

    cacheFile (Default: ${project.build.directory}/war/work/webapp-cache.xml)
      Required: true
      The file containing the webapp structure cache.

    classesClassifier (Default: classes)
      The classifier to use for the attached classes artifact.

    classifier
      Classifier to add to the generated WAR. If given, the artifact will be an
      attachment instead. The classifier will not be applied to the JAR file of
      the project - only to the WAR file.

    containerConfigXML
      The path to a configuration file for the servlet container. Note that the
      file name may be different for different servlet containers. Apache
      Tomcat uses a configuration file named context.xml. The file will be
      copied to the META-INF directory.

    delimiters
      Set of delimiters for expressions to filter within the resources. These
      delimiters are specified in the form 'beginToken*endToken'. If no '*' is
      given, the delimiter is assumed to be the same for start and end.
      
      So, the default filtering delimiters might be specified as:
      
      Since the '@' delimiter is the same on both ends, we don't need to
      specify '@*@' (though we can).

    dependentWarExcludes
      The comma separated list of tokens to exclude when doing a WAR overlay.
      Default is Overlay.DEFAULT_EXCLUDES

    dependentWarIncludes
      The comma separated list of tokens to include when doing a WAR overlay.
      Default is Overlay.DEFAULT_INCLUDES

    escapedBackslashesInFilePath (Default: false)
      To escape interpolated values with Windows path c:\foo\bar will be
      replaced with c:\\foo\\bar.

    escapeString
      Expression preceded with this String won't be interpolated. \${foo} will
      be replaced with ${foo}.

    failOnMissingWebXml
      Whether or not to fail the build if the web.xml file is missing. Set to
      false if you want your WAR built without a web.xml file. This may be
      useful if you are building an overlay that has no web.xml file.
      Starting with 3.1.0, this property defaults to false if the project
      depends on the Servlet 3.0 API or newer.

    filteringDeploymentDescriptors (Default: false)
      To filter deployment descriptors. Disabled by default.

    filters
      Filters (property files) to include during the interpolation of the
      pom.xml.

    includeEmptyDirectories (Default: false)
      (no description available)

    nonFilteredFileExtensions
      A list of file extensions that should not be filtered. Will be used when
      filtering webResources and overlays.

    outputDirectory (Default: ${project.build.directory})
      Required: true
      The directory for the generated WAR.

    outputFileNameMapping
      The file name mapping to use when copying libraries and TLDs. If no file
      mapping is set (default) the files are copied with their standard names.

    overlays
      The overlays to apply. Each overlay element may contain:
      - id (defaults to currentBuild)
      - groupId (if this and artifactId are null, then the current project is
        treated as its own overlay)
      - artifactId (see above)
      - classifier
      - type
      - includes (a list of string patterns)
      - excludes (a list of string patterns)
      - filtered (defaults to false)
      - skip (defaults to false)
      - targetPath (defaults to root of webapp structure)

    packagingExcludes
      The comma separated list of tokens to exclude from the WAR before
      packaging. This option may be used to implement the skinny WAR use case.
      Note that you can use the Java Regular Expressions engine to include and
      exclude specific pattern using the expression %regex[]. Hint: read the
      about (?!Pattern).

    packagingIncludes
      The comma separated list of tokens to include in the WAR before
      packaging. By default everything is included. This option may be used to
      implement the skinny WAR use case. Note that you can use the Java Regular
      Expressions engine to include and exclude specific pattern using the
      expression %regex[].

    primaryArtifact (Default: true)
      Whether this is the main artifact being built. Set to false if you don't
      want to install or deploy it to the local repository instead of the
      default one in an execution.

    recompressZippedFiles (Default: true)
      Indicates if zip archives (jar,zip etc) being added to the war should be
      compressed again. Compressing again can result in smaller archive size,
      but gives noticeably longer execution time.

    resourceEncoding (Default: ${project.build.sourceEncoding})
      The encoding to use when copying filtered web resources.

    skip (Default: false)
      User property: maven.war.skip
      You can skip the execution of the plugin if you need to. Its use is NOT
      RECOMMENDED, but quite convenient on occasion.

    supportMultiLineFiltering (Default: false)
      Stop searching endToken at the end of line

    useCache (Default: false)
      Whether the cache should be used to save the status of the webapp across
      multiple runs. Experimental feature so disabled by default.

    useDefaultDelimiters (Default: true)
      Use default delimiters in addition to custom delimiters, if any.

    useJvmChmod (Default: true)
      use jvmChmod rather that cli chmod and forking process

    warSourceDirectory (Default: ${basedir}/src/main/webapp)
      Required: true
      Single directory for extra files to include in the WAR. This is where you
      place your JSP files.

    warSourceExcludes
      The comma separated list of tokens to exclude when copying the content of
      the warSourceDirectory.

    warSourceIncludes (Default: **)
      The comma separated list of tokens to include when copying the content of
      the warSourceDirectory.

    webappDirectory (Default:
    ${project.build.directory}/${project.build.finalName})
      Required: true
      The directory where the webapp is built.

    webResources
      The list of webResources we want to transfer.

    webXml
      The path to the web.xml file to use.

    workDirectory (Default: ${project.build.directory}/war/work)
      Required: true
      Directory to unpack dependent WARs into if needed.


[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.960 s
[INFO] Finished at: 2017-08-03T14:33:18+08:00
[INFO] Final Memory: 10M/155M
[INFO] ------------------------------------------------------------------------			
			
			
			
MacBook-Pro:api.netkiller.cn neo$ mvn help:describe \
	-DgroupId=org.springframework.boot \
	-DartifactId=spring-boot-maven-plugin \
	-Ddetail=true			
			
			

2.3.3. Maven 仓库

http://search.maven.org/

http://mvnrepository.com/

本地下载目录

$ ls ~/.m2
		

2.3.4. pom.xml

2.3.4.1. properties

定义 properties

			
<properties>
    <spring.version>4.0.1.RELEASE</spring.version>
</properties>
			
			

引用 properties

			
  <!-- Spring dependencies -->
   <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-core</artifactId>
    <version>${spring.version}</version>
  </dependency>
			
			

例 2.1. Maven properties

pom.xml 文件

				
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

 <modelVersion>4.0.0</modelVersion>
 <groupId>com.javahash.web</groupId>
 <artifactId>Spring4MVCHelloWorld</artifactId>
 <packaging>war</packaging>
 <version>1.0-SNAPSHOT</version>
 <name>Spring4MVCHelloWorld Maven Webapp</name>
 <url>http://maven.apache.org</url>

 <properties>
    <spring.version>4.0.1.RELEASE</spring.version>
 </properties>

 <dependencies>

    <dependency>
     <groupId>junit</groupId>
     <artifactId>junit</artifactId>
     <version>4.12</version>
     <scope>test</scope>
    </dependency>

   <!-- Spring dependencies -->
   <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-core</artifactId>
    <version>${spring.version}</version>
  </dependency>

 <dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring-web</artifactId>
   <version>${spring.version}</version>
 </dependency>

 <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>
    <version>${spring.version}</version>
 </dependency>
</dependencies>

 <build>
 <finalName>Spring4MVCHelloWorld</finalName>
 </build>
</project>
				
				

2.3.4.1.1. java.version
				
	<properties>
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
         <java.version>1.8</java.version>
    </properties>
				
				

2.3.4.2. dependencies

			
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
    	<groupId>org.apache.struts</groupId>
    	<artifactId>struts2-core</artifactId>
    	<version>2.3.24.1</version>
    </dependency>
  </dependencies>
			
			

2.3.4.3. dependencyManagement

声明父项目引用包的版本号。

			
	<dependencyManagement>
		<dependencies>
			<dependency>
				<groupId>org.springframework.cloud</groupId>
				<artifactId>spring-cloud-netflix</artifactId>
				<version>1.3.5.RELEASE</version>
				<type>pom</type>
				<scope>import</scope>
			</dependency>
			<dependency>
				<groupId>org.springframework.cloud</groupId>
				<artifactId>spring-cloud-config</artifactId>
				<version>1.3.3.RELEASE</version>
				<type>pom</type>
				<scope>import</scope>
			</dependency>
		</dependencies>
	</dependencyManagement>			
			
			

2.3.4.4. build

2.3.4.4.1. finalName

最终 jar 包得名字

			
<build>
		<finalName>crawler</finalName>
</build>
			
				
2.3.4.4.2. sourceDirectory

编译源码目录

			
<sourceDirectory>src</sourceDirectory>				
			
				
2.3.4.4.3. resources 文件处理

resources 用来处理 src/main/resources 目录中得内容

			
		<resources>
			<resource>
				<directory>src/main/resources</directory>
				<targetPath>${project.build.directory}/conf</targetPath>
			</resource>
			<resource>
				<directory>src/main/resources</directory>
				<excludes>
					<exclude>development.properties</exclude>
				</excludes>
			</resource>
			<resource>
				<directory>src/main/resources</directory>
				<includes>
					<include>development.properties</include>
				</includes>
				<targetPath>resources</targetPath>
			</resource>
			
			<resource>
				<directory>lib</directory>
				<includes>
					<include>**/*.sh</include>
					<include>**/*.bat</include>
				</includes>
				<targetPath>${project.build.directory}/lib</targetPath>
			</resource>
		</resources>
				
			
				
2.3.4.4.3.1. resources

将资源文件编译后复制到 WEB-INF/classes 目录中

				
		<resources>
			<resource>
				<directory>src/resources</directory>
			</resource>
		</resources>			
				
					

include / exclude

				
<resources>  
    <!-- Filter jdbc.properties & mail.properties. NOTE: We don't filter applicationContext-infrastructure.xml,   
        let it go with spring's resource process mechanism. -->  
    <resource>  
        <directory>src/main/resources</directory>  
        <filtering>true</filtering>  
        <includes>  
            <include>jdbc.properties</include>  
            <include>mail.properties</include>  
        </includes>  
    </resource>  
    <!-- Include other files as resources files. -->  
    <resource>  
        <directory>src/main/resources</directory>  
        <filtering>false</filtering>  
        <excludes>  
            <exclude>jdbc.properties</exclude>  
            <exclude>mail.properties</exclude>  
        </excludes>  
    </resource>  
</resources>
				
					

2.3.4.5. plugins

2.3.4.5.1. 跳过Unit test
			
<project>
  [...]
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
          <skip>true</skip>
        </configuration>
      </plugin>
    </plugins>
  </build>
  [...]
</project>			
			
				
2.3.4.5.2. maven-shade-plugin
				
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-shade-plugin</artifactId>
				<version>1.4</version>
				<executions>
					<execution>
						<phase>package</phase>
						<goals>
							<goal>shade</goal>
						</goals>
						<configuration>
							<transformers>
								<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
									<mainClass>cn.netkiller.Oracle</mainClass>
								</transformer>
							</transformers>
						</configuration>
					</execution>
				</executions>
			</plugin>				
				
				

2.3.5. plugins

2.3.5.1. maven-compiler-plugin

禁止编译警告 -Xlint:unchecked,-Xlint:deprecation

			
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.1</version>
				<configuration>
					<source>1.8</source>
					<target>1.8</target>
					<encoding>UTF-8</encoding>
					<compilerArgs>
						<arg>-verbose</arg>
						<arg>-Xlint:unchecked</arg>
						<arg>-Xlint:deprecation</arg>
					</compilerArgs>
				</configuration>
			</plugin>
			
			
			
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.1</version>
				<configuration>
					<source>1.8</source>
					<target>1.8</target>
					<encoding>UTF-8</encoding>
					<compilerArgs>
						<arg>-verbose</arg>
						<arg>-Xlint:unchecked</arg>
						<arg>-Xlint:deprecation</arg>
						<arg>-bootclasspath</arg>
						<arg>${env.JAVA_HOME}/jre/lib/rt.jar</arg>
						<arg>-extdirs</arg>
						<arg>${project.basedir}/libs</arg>
					</compilerArgs>
				</configuration>
			</plugin>
			
			

compilerArgs可以实现编译参数的传递

2.3.5.2. maven-war-plugin

设置 war 文件名 warName

			
<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.3</version>
        <configuration>
          <warName>bird.war</warName>
        </configuration>
      </plugin>
    </plugins>
  </build>
  ...
</project>			
			
			

2.3.5.3. maven-antrun-plugin

查看可用的pom定义

			
or alternatively, we can use an external build.xml.

<project>
  <modelVersion>4.0.0</modelVersion>
  <artifactId>my-test-app</artifactId>
  <groupId>my-test-group</groupId>
  <version>1.0-SNAPSHOT</version>

  <build>
    <plugins>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>1.8</version>
        <executions>
          <execution>
            <id>compile</id>
            <phase>compile</phase>
            <configuration>
              <target>
                <property name="compile_classpath" refid="maven.compile.classpath"/>
                <property name="runtime_classpath" refid="maven.runtime.classpath"/>
                <property name="test_classpath" refid="maven.test.classpath"/>
                <property name="plugin_classpath" refid="maven.plugin.classpath"/>

                <echo message="compile classpath: ${compile_classpath}"/>
                <echo message="runtime classpath: ${runtime_classpath}"/>
                <echo message="test classpath:    ${test_classpath}"/>
                <echo message="plugin classpath:  ${plugin_classpath}"/>

                <ant antfile="${basedir}/build.xml">
                  <target name="test"/>
                </ant>
              </target>
            </configuration>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

The build.xml:

<?xml version="1.0"?>
<project name="test6">

    <target name="test">

      <echo message="compile classpath: ${compile_classpath}"/>
      <echo message="runtime classpath: ${runtime_classpath}"/>
      <echo message="test classpath:    ${test_classpath}"/>
      <echo message="plugin classpath:  ${plugin_classpath}"/>

    </target>

</project>
			
			

2.3.5.4. maven-install-plugin

			
		<plugin>
			<groupId>org.apache.maven.plugins</groupId>
			<artifactId>maven-install-plugin</artifactId>
			<version>2.5.2</version>
			<inherited>false</inherited>
			<executions>
				<execution>
					<id>install:com.oracle:ojdbc6:11g</id>
					<phase>validate</phase>
					<goals>
						<goal>install-file</goal>
					</goals>
					<configuration>
						<file>${project.basedir}/lib/ojdbc6.jar</file>
						<groupId>com.oracle</groupId>
						<artifactId>ojdbc6</artifactId>
						<version>11.2.0.3</version>
						<packaging>jar</packaging>
						<createChecksum>true</createChecksum>
						<generatePom>true</generatePom>
					</configuration>
				</execution>
			</executions>
		</plugin>
			
			

2.3.5.5. maven-surefire-plugin

			
	<plugin>
		<groupId>org.apache.maven.plugins</groupId>
		<artifactId>maven-surefire-plugin</artifactId>
		<version>2.20</version>
		<configuration>
			<skip>true</skip>
		</configuration>
	</plugin>		
			
			

2.3.5.6. maven-deploy-plugin

			
			<plugin>
		      <!--skip deploy (this is just a test module) -->
		      <artifactId>maven-deploy-plugin</artifactId>
		      <configuration>
		        <skip>true</skip>
		      </configuration>
	        </plugin>			
			
			

2.3.5.7. maven-jar-plugin

指定jar创建目录,下面配置运行 mvn package 后将在 target 目录下创建一个 project 目录。

			
	<plugin>
		<groupId>org.apache.maven.plugins</groupId>
		<artifactId>maven-jar-plugin</artifactId>
		<version>2.3.1</version>
		<configuration>
			<outputDirectory>${project.build.directory}/project</outputDirectory>
		</configuration>
	</plugin>
			
			

知道 jar 文件的默认 mainClass

			
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-jar-plugin</artifactId>
				<version>2.6</version>
				<configuration>
					<outputDirectory>${project.build.directory}/project/lib</outputDirectory>
					<archive>
						<manifest>
							<addClasspath>true</addClasspath>
							<classpathPrefix>lib/</classpathPrefix>
							<mainClass>cn.netkiller.web.App</mainClass>
						</manifest>
					</archive>
				</configuration>
			</plugin>
			
			

2.3.5.8. maven-dependency-plugin

			
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-dependency-plugin</artifactId>
				<!-- <version>2.10</version> -->
				<executions>
					<execution>
						<id>copy-dependencies</id>
						<phase>package</phase>
						<goals>
							<goal>copy-dependencies</goal>
						</goals>
						<configuration>
							<!-- 把依赖的所有maven jar包拷贝到lib目录中(这样所有的jar包都在lib目录中) -->
							<outputDirectory>${project.build.directory}/project/lib</outputDirectory>
							<overWriteReleases>false</overWriteReleases>
							<overWriteSnapshots>false</overWriteSnapshots>
							<overWriteIfNewer>true</overWriteIfNewer>
						</configuration>
					</execution>
				</executions>
			</plugin>
			
			

2.3.5.9. spring-boot-maven-plugin

			
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
				<configuration>
					<mainClass>cn.netkiller.Application</mainClass>
				</configuration>
			</plugin>
			
			
			
MacBook-Pro:api.netkiller.cn neo$ mvn help:describe -DgroupId=org.springframework.boot                   -DartifactId=spring-boot-maven-plugin                   -Ddetail=true
[INFO] Scanning for projects...
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] Building api 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-help-plugin:2.2:describe (default-cli) @ api ---
[INFO] org.springframework.boot:spring-boot-maven-plugin:1.5.6.RELEASE

Name: Spring Boot Maven Plugin
Description: Spring Boot Maven Plugin
Group Id: org.springframework.boot
Artifact Id: spring-boot-maven-plugin
Version: 1.5.6.RELEASE
Goal Prefix: spring-boot

This plugin has 6 goals:

spring-boot:build-info
  Description: Generate a build-info.properties file based the content of the
    current MavenProject.
  Implementation: org.springframework.boot.maven.BuildInfoMojo
  Language: java
  Bound to phase: generate-resources

  Available parameters:

    additionalProperties
      Additional properties to store in the build-info.properties. Each entry
      is prefixed by build. in the generated build-info.properties.

    outputFile (Default:
    ${project.build.outputDirectory}/META-INF/build-info.properties)
      The location of the generated build-info.properties.

spring-boot:help
  Description: Display help information on spring-boot-maven-plugin.
    Call mvn spring-boot:help -Ddetail=true -Dgoal=<goal-name> to display
    parameter details.
  Implementation: org.springframework.boot.maven.HelpMojo
  Language: java

  Available parameters:

    detail (Default: false)
      User property: detail
      If true, display all settable properties for each goal.

    goal
      User property: goal
      The name of the goal for which to show help. If unspecified, all goals
      will be displayed.

    indentSize (Default: 2)
      User property: indentSize
      The number of spaces per indentation level, should be positive.

    lineLength (Default: 80)
      User property: lineLength
      The maximum length of a display line, should be positive.

spring-boot:repackage
  Description: Repackages existing JAR and WAR archives so that they can be
    executed from the command line using java -jar. With layout=NONE can also
    be used simply to package a JAR with nested dependencies (and no main
    class, so not executable).
  Implementation: org.springframework.boot.maven.RepackageMojo
  Language: java
  Bound to phase: package

  Available parameters:

    attach (Default: true)
      Attach the repackaged archive to be installed and deployed.

    classifier
      Classifier to add to the artifact generated. If given, the artifact will
      be attached with that classifier and the main artifact will be deployed
      as the main artifact. If this is not given (default), it will replace the
      main artifact and only the repackaged artifact will be deployed.
      Attaching the artifact allows to deploy it alongside to the original one,
      see the maven documentation for more details.

    embeddedLaunchScript
      The embedded launch script to prepend to the front of the jar if it is
      fully executable. If not specified the 'Spring Boot' default script will
      be used.

    embeddedLaunchScriptProperties
      Properties that should be expanded in the embedded launch script.

    excludeArtifactIds
      User property: excludeArtifactIds
      Comma separated list of artifact names to exclude (exact match).

    excludeDevtools (Default: true)
      Exclude Spring Boot devtools from the repackaged archive.

    excludeGroupIds
      User property: excludeGroupIds
      Comma separated list of groupId names to exclude (exact match).

    excludes
      Collection of artifact definitions to exclude. The Exclude element
      defines a groupId and artifactId mandatory properties and an optional
      classifier property.

    executable (Default: false)
      Make a fully executable jar for *nix machines by prepending a launch
      script to the jar.
      Currently, some tools do not accept this format so you may not always be
      able to use this technique. For example, jar -xf may silently fail to
      extract a jar or war that has been made fully-executable. It is
      recommended that you only enable this option if you intend to execute it
      directly, rather than running it with java -jar or deploying it to a
      servlet container.

    finalName (Default: ${project.build.finalName})
      Required: true
      Name of the generated archive.

    includes
      Collection of artifact definitions to include. The Include element
      defines a groupId and artifactId mandatory properties and an optional
      classifier property.

    includeSystemScope (Default: false)
      Include system scoped dependencies.

    layout
      The type of archive (which corresponds to how the dependencies are laid
      out inside it). Possible values are JAR, WAR, ZIP, DIR, NONE. Defaults to
      a guess based on the archive type.

    layoutFactory
      The layout factory that will be used to create the executable archive if
      no explicit layout is set. Alternative layouts implementations can be
      provided by 3rd parties.

    mainClass
      The name of the main class. If not specified the first compiled class
      found that contains a 'main' method will be used.

    outputDirectory (Default: ${project.build.directory})
      Required: true
      Directory containing the generated archive.

    requiresUnpack
      A list of the libraries that must be unpacked from fat jars in order to
      run. Specify each library as a <dependency> with a <groupId> and a
      <artifactId> and they will be unpacked at runtime.

    skip (Default: false)
      User property: skip
      Skip the execution.

spring-boot:run
  Description: Run an executable archive application.
  Implementation: org.springframework.boot.maven.RunMojo
  Language: java
  Bound to phase: validate
  Before this mojo executes, it will call:
    Phase: 'test-compile'

  Available parameters:

    addResources (Default: false)
      User property: run.addResources
      Add maven resources to the classpath directly, this allows live in-place
      editing of resources. Duplicate resources are removed from target/classes
      to prevent them to appear twice if ClassLoader.getResources() is called.
      Please consider adding spring-boot-devtools to your project instead as it
      provides this feature and many more.

    agent
      User property: run.agent
      Path to agent jar. NOTE: the use of agents means that processes will be
      started by forking a new JVM.

    arguments
      User property: run.arguments
      Arguments that should be passed to the application. On command line use
      commas to separate multiple arguments.

    classesDirectory (Default: ${project.build.outputDirectory})
      Required: true
      Directory containing the classes and resource files that should be
      packaged into the archive.

    excludeArtifactIds
      User property: excludeArtifactIds
      Comma separated list of artifact names to exclude (exact match).

    excludeGroupIds
      User property: excludeGroupIds
      Comma separated list of groupId names to exclude (exact match).

    excludes
      Collection of artifact definitions to exclude. The Exclude element
      defines a groupId and artifactId mandatory properties and an optional
      classifier property.

    folders
      Additional folders besides the classes directory that should be added to
      the classpath.

    fork
      User property: fork
      Flag to indicate if the run processes should be forked. fork is
      automatically enabled if an agent, jvmArguments or working directory are
      specified, or if devtools is present.

    includes
      Collection of artifact definitions to include. The Include element
      defines a groupId and artifactId mandatory properties and an optional
      classifier property.

    jvmArguments
      User property: run.jvmArguments
      JVM arguments that should be associated with the forked process used to
      run the application. On command line, make sure to wrap multiple values
      between quotes. NOTE: the use of JVM arguments means that processes will
      be started by forking a new JVM.

    mainClass
      The name of the main class. If not specified the first compiled class
      found that contains a 'main' method will be used.

    noverify
      User property: run.noverify
      Flag to say that the agent requires -noverify.

    profiles
      User property: run.profiles
      The spring profiles to activate. Convenience shortcut of specifying the
      'spring.profiles.active' argument. On command line use commas to separate
      multiple profiles.

    skip (Default: false)
      User property: skip
      Skip the execution.

    useTestClasspath (Default: false)
      User property: useTestClasspath
      Flag to include the test classpath when running.

    workingDirectory
      User property: run.workingDirectory
      Current working directory to use for the application. If not specified,
      basedir will be used. NOTE: the use of working directory means that
      processes will be started by forking a new JVM.

spring-boot:start
  Description: Start a spring application. Contrary to the run goal, this
    does not block and allows other goal to operate on the application. This
    goal is typically used in integration test scenario where the application
    is started before a test suite and stopped after.
  Implementation: org.springframework.boot.maven.StartMojo
  Language: java
  Bound to phase: pre-integration-test

  Available parameters:

    addResources (Default: false)
      User property: run.addResources
      Add maven resources to the classpath directly, this allows live in-place
      editing of resources. Duplicate resources are removed from target/classes
      to prevent them to appear twice if ClassLoader.getResources() is called.
      Please consider adding spring-boot-devtools to your project instead as it
      provides this feature and many more.

    agent
      User property: run.agent
      Path to agent jar. NOTE: the use of agents means that processes will be
      started by forking a new JVM.

    arguments
      User property: run.arguments
      Arguments that should be passed to the application. On command line use
      commas to separate multiple arguments.

    classesDirectory (Default: ${project.build.outputDirectory})
      Required: true
      Directory containing the classes and resource files that should be
      packaged into the archive.

    excludeArtifactIds
      User property: excludeArtifactIds
      Comma separated list of artifact names to exclude (exact match).

    excludeGroupIds
      User property: excludeGroupIds
      Comma separated list of groupId names to exclude (exact match).

    excludes
      Collection of artifact definitions to exclude. The Exclude element
      defines a groupId and artifactId mandatory properties and an optional
      classifier property.

    folders
      Additional folders besides the classes directory that should be added to
      the classpath.

    fork
      User property: fork
      Flag to indicate if the run processes should be forked. fork is
      automatically enabled if an agent, jvmArguments or working directory are
      specified, or if devtools is present.

    includes
      Collection of artifact definitions to include. The Include element
      defines a groupId and artifactId mandatory properties and an optional
      classifier property.

    jmxName
      The JMX name of the automatically deployed MBean managing the lifecycle
      of the spring application.

    jmxPort
      The port to use to expose the platform MBeanServer if the application
      needs to be forked.

    jvmArguments
      User property: run.jvmArguments
      JVM arguments that should be associated with the forked process used to
      run the application. On command line, make sure to wrap multiple values
      between quotes. NOTE: the use of JVM arguments means that processes will
      be started by forking a new JVM.

    mainClass
      The name of the main class. If not specified the first compiled class
      found that contains a 'main' method will be used.

    maxAttempts
      The maximum number of attempts to check if the spring application is
      ready. Combined with the 'wait' argument, this gives a global timeout
      value (30 sec by default)

    noverify
      User property: run.noverify
      Flag to say that the agent requires -noverify.

    profiles
      User property: run.profiles
      The spring profiles to activate. Convenience shortcut of specifying the
      'spring.profiles.active' argument. On command line use commas to separate
      multiple profiles.

    skip (Default: false)
      User property: skip
      Skip the execution.

    useTestClasspath (Default: false)
      User property: useTestClasspath
      Flag to include the test classpath when running.

    wait
      The number of milli-seconds to wait between each attempt to check if the
      spring application is ready.

    workingDirectory
      User property: run.workingDirectory
      Current working directory to use for the application. If not specified,
      basedir will be used. NOTE: the use of working directory means that
      processes will be started by forking a new JVM.

spring-boot:stop
  Description: Stop a spring application that has been started by the 'start'
    goal. Typically invoked once a test suite has completed.
  Implementation: org.springframework.boot.maven.StopMojo
  Language: java
  Bound to phase: post-integration-test

  Available parameters:

    fork
      User property: fork
      Flag to indicate if process to stop was forked. By default, the value is
      inherited from the MavenProject. If it is set, it must match the value
      used to StartMojo start the process.

    jmxName
      The JMX name of the automatically deployed MBean managing the lifecycle
      of the application.

    jmxPort
      The port to use to lookup the platform MBeanServer if the application has
      been forked.

    skip (Default: false)
      User property: skip
      Skip the execution.


[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.976 s
[INFO] Finished at: 2017-08-03T15:05:53+08:00
[INFO] Final Memory: 12M/155M
[INFO] ------------------------------------------------------------------------			
			
			




原文出处:Netkiller 系列 手札
本文作者:陈景峯
转载请与作者联系,同时请务必标明文章原始出处和作者信息及本声明。

目录
相关文章
|
数据可视化 Java 项目管理
|
7天前
|
Java 测试技术 项目管理
maven 用来做什么
Maven 是一款流行的 Java 项目管理工具,支持项目构建、依赖管理和信息管理。它通过自动化构建流程、中央与本地仓库的依赖管理、项目元数据维护、生成各类项目报告及协助项目部署,极大提升了开发效率和项目管理的便捷性。
23 5
|
6月前
|
Java Maven 开发工具
Maven 特点
Maven是一个强大的Java项目管理工具,其特点包括:遵循统一规范的项目设置,支持跨工程共享;具备自动更新依赖的功能,并拥有庞大的库资源;可扩展,允许用户编写Java或脚本插件;几乎无需额外配置即可使用新功能;基于模型的构建系统,能自动生成JAR、WAR等格式的输出;能创建一致性项目站点,包含标准报告和自定义文档;支持发布管理和源代码管理集成;具有向后兼容性,方便旧版本迁移;子项目能继承父项目的依赖;并行构建提升编译效率;提供改进的错误报告,链接到详细解释页面。
|
6月前
|
Java 应用服务中间件 项目管理
Maven详解
Apache Maven是一个强大的Java项目管理和构建工具,它简化了项目结构、依赖管理、构建过程。Maven遵循约定优于配置原则,提供标准项目模板,自动处理依赖下载和版本控制。通过POM(Project Object Model)文件,开发人员声明项目属性、依赖、构建配置等。Maven支持多模块管理、文档生成、版本管理和构建报告。使用Maven,可以更高效地管理复杂项目,避免手动管理依赖带来的问题。此外,Maven的配置文件(settings.xml)允许设置本地仓库、中央仓库镜像和JDK版本等。
71 1
Maven详解
|
6月前
|
存储 IDE Java
Maven
Maven
51 0
|
7月前
|
存储 Java 关系型数据库
|
7月前
|
存储 XML Java
maven
maven
346 0
|
Java 测试技术 数据库连接
|
Java Maven
|
Java Apache 项目管理
maven
Maven 是一个流行的 Java 项目管理工具,它可以帮助开发人员管理项目依赖、构建项目、运行测试、打包和部署项目等。Maven 的主要功能包括:
292 1