本文共 57133 字,大约阅读时间需要 190 分钟。
$ sudo apt-get install maven2$ mvn -versionApache Maven 2.2.1 (rdebian-4)Java version: 1.6.0_22Java home: /usr/lib/jvm/java-6-openjdk/jreDefault locale: en_US, platform encoding: UTF-8OS 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/"
curl -s https://raw.githubusercontent.com/oscm/shell/master/lang/java/maven/maven.sh | bash
查看可用的pom定义
mvn help:effective-pom
创建 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
清楚
$ mvn clean
编译项目的源代码
$ mvn compile
编译测试的源代码
mvn test-compile
运行测试
$ mvn test
打包但不测试
mvn -D maven.test.skip=true package
将编译后的代码打包
$ mvn package
$ ls target/*.wartarget/www.netkiller.cn-0.0.1-SNAPSHOT.war
将项目打包后安装到本地仓库,可以作为其它项目的本地依赖。
$ mvn install
跳过测试
mvn install -Dmaven.test.skip=true
安装本地jar文件到Maven的.m2库中。
mvn install:install-file -Dfile=Path/to/your.jar} -DgroupId=com.example -DartifactId=project -Dversion=1.2.0 -Dpackaging=jar
mvn compile war:war
mvn compile war:exploded
mvn compile war:inplace
$ mvn exec:java -Dexec.mainClass="cn.netkiller.Test"
$ 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] ------------------------------------------------------------------------
[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] ------------------------------------------------------------------------
$ 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.jaraopalliance-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.jaraspectjweaver-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.jarclassmate-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.jardom4j-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.jargroovy-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.jarhibernate-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.jarhibernate-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.jarhibernate-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.jarhibernate-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.jarhibernate-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.jarjackson-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.jarjackson-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.jarjackson-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.jarjandex-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
$ mvn dependency:analyze
mvn dependency:sources
mvn -Djar.finalName=myCustomName package
mvn jar:jar -Djar.finalName=custom-jar-name
显示插件的详细信息
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.0Name: Apache Maven WAR PluginDescription: Builds a Web Application Archive (WAR) file from the project output and its dependencies.Group Id: org.apache.maven.pluginsArtifact Id: maven-war-pluginVersion: 3.1.0Goal Prefix: warThis 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: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 ${*} @ 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= 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: 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 ${*} @ 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
http://search.maven.org/
http://mvnrepository.com/
本地下载目录
$ ls ~/.m2
定义 properties
4.0.1.RELEASE
引用 properties
org.springframework spring-core ${spring.version}
例 2.1. Maven properties
pom.xml 文件
4.0.0 com.javahash.web Spring4MVCHelloWorld war 1.0-SNAPSHOT Spring4MVCHelloWorld Maven Webapp http://maven.apache.org 4.0.1.RELEASE junit junit 4.12 test org.springframework spring-core ${spring.version} org.springframework spring-web ${spring.version} org.springframework spring-webmvc ${spring.version} Spring4MVCHelloWorld
UTF-8 1.8
junit junit 3.8.1 test org.apache.struts struts2-core 2.3.24.1
声明父项目引用包的版本号。
org.springframework.cloud spring-cloud-netflix 1.3.5.RELEASE pom import org.springframework.cloud spring-cloud-config 1.3.3.RELEASE pom import
最终 jar 包得名字
crawler
编译源码目录
src
resources 用来处理 src/main/resources 目录中得内容
src/main/resources ${project.build.directory}/conf src/main/resources development.properties src/main/resources development.properties resources lib **/*.sh **/*.bat ${project.build.directory}/lib
将资源文件编译后复制到 WEB-INF/classes 目录中
src/resources
include / exclude
src/main/resources true jdbc.properties mail.properties src/main/resources false jdbc.properties mail.properties
[...] [...] org.apache.maven.plugins maven-surefire-plugin true
org.apache.maven.plugins maven-shade-plugin 1.4 package shade cn.netkiller.Oracle
禁止编译警告 -Xlint:unchecked,-Xlint:deprecation
org.apache.maven.plugins maven-compiler-plugin 3.1
org.apache.maven.plugins maven-compiler-plugin 3.1
compilerArgs可以实现编译参数的传递
设置 war 文件名 warName
... ... org.apache.maven.plugins maven-war-plugin 2.3 bird.war
查看可用的pom定义
or alternatively, we can use an external build.xml.The build.xml: 4.0.0 my-test-app my-test-group 1.0-SNAPSHOT org.apache.maven.plugins maven-antrun-plugin 1.8 compile compile run
org.apache.maven.plugins maven-install-plugin 2.5.2 false install:com.oracle:ojdbc6:11g validate install-file ${project.basedir}/lib/ojdbc6.jar com.oracle ojdbc6 11.2.0.3 jar true true
org.apache.maven.plugins maven-surefire-plugin 2.20 true
maven-deploy-plugin true
指定jar创建目录,下面配置运行 mvn package 后将在 target 目录下创建一个 project 目录。
org.apache.maven.plugins maven-jar-plugin 2.3.1 ${project.build.directory}/project
知道 jar 文件的默认 mainClass
org.apache.maven.plugins maven-jar-plugin 2.6 ${project.build.directory}/project/lib true lib/ cn.netkiller.web.App
org.apache.maven.plugins maven-dependency-plugin copy-dependencies package copy-dependencies ${project.build.directory}/project/lib false false true
org.springframework.boot spring-boot-maven-plugin cn.netkiller.Application
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.RELEASEName: Spring Boot Maven PluginDescription: Spring Boot Maven PluginGroup Id: org.springframework.bootArtifact Id: spring-boot-maven-pluginVersion: 1.5.6.RELEASEGoal Prefix: spring-bootThis 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=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 with a and a 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] ------------------------------------------------------------------------