maven 包管理平台-07-plugins 常见插件介绍
拓展阅读
maven 包管理平台-01-maven 入门介绍 + Maven、Gradle、Ant、Ivy、Bazel 和 SBT 的详细对比表格
maven 包管理平台-02-windows 安装配置 + mac 安装配置
maven 包管理平台-03-maven project maven 项目的创建入门
maven 包管理平台-04-maven archetype 项目原型
maven 包管理平台-05-multi module 多模块
maven 包管理平台-06-常用技巧 实时更新快照/乱码问题/下载很慢/包依赖解决包冲突/如何导入本地 jar
maven 包管理平台-08-nexus 自己搭建 maven 仓库
maven 插件
Maven 在其核心是一个插件执行框架;所有工作都由插件完成。
寻找要执行的特定目标吗?此页面列出了核心插件和其他插件。
有构建和报告插件:
构建(Build) 插件将在构建过程中执行,它们应该在 POM 中的 `````` 元素中进行配置。
报告(Reporting) 插件将在站点生成期间执行,它们应该在 POM 中的 `````` 元素中进行配置。因为报告插件的结果是生成站点的一部分,所以报告插件应该同时进行国际化和本地化。您可以阅读更多关于插件本地化的信息以及您可以如何帮助的内容。
核心插件
这些插件对应于默认的核心阶段(即 clean,compile 等)。
它们也可能有多个目标。
compiler
编译 Java 源代码。
org.apache.maven.plugins
maven-compiler-plugin
${maven-compiler-plugin.version}
1.8
1.8
surefire
在隔离的类加载器中运行 JUnit 单元测试。
org.apache.maven.plugins
maven-surefire-plugin
${maven-surefire-plugin.version}
true
true
报告插件
生成报告的插件,在 POM 中配置为报告,并在站点生成生命周期下运行。
javadoc
为项目生成 Javadoc 文档。
org.apache.maven.plugins
maven-javadoc-plugin
2.9.1
true
../doc
myapidocs
${java.home}/../bin/javadoc
Description
a
用途
其他
许多其他项目提供了它们自己的 Maven 插件。
tomcat7
运行 Apache Tomcat 容器以进行快速 Web 应用程序开发。
UTF-8
org.apache.tomcat.maven
tomcat7-maven-plugin
${plugin.tomcat.version}
8081
/
${project.build.sourceEncoding}
Versions
mvn versions:set -DnewVersion=1.0.1-SNAPSHOT
- commit
mvn versions:commit
- revert
mvn versions:revert
正确修改方法:
(1) 修改父类
mvn versions:set -DgroupId=com.framework -DartifactId=framework* -DoldVersion=* -DnewVersion=1.0.2-SNAPSHOT
(2) 修改子类
mvn -N versions:update-child-modules
Auto-Config
Import in maven
1.2
com.alibaba.citrus.tool
autoconfig-maven-plugin
${autoconfig-plugin-version}
${project.artifact.file}
-->
true
-->
${project.build.directory}/${project.build.finalName}
-->
package
autoconfig
跳过执行
$ mvn install –Dautoconfig.skip
- 想使用配置文件
(1) 直接将生成的配置文件 antx.properties
视为配置文件使用。放在本地。
(2) 打成war包之后可以自动属性替换掉。
1、 maven war struct:
war-project(源目录结构) -> war-project.war(目标目录结构)
│ pom.xml
│
└─src
└─main
├─java
├─resources -> /WEB-INF/classes
│ file1.xml file1.xml
│ file2.xml file2.xml
│
└─webapp -> /
├─META-INF -> /META-INF
│ └─autoconf -> /META-INF/autoconf
│ auto-config.xml auto-config.xml
│
└─WEB-INF -> /WEB-INF
web.xml web.xml
file3.xml file3.xml
/META-INF/autoconf
目录用来存放AutoConfig的描述文件,以及可选的模板文件。auto-config.xml
是用来指导AutoConfig行为的关键描述文件。
2、 maven jar struct
jar-project(源目录结构) -> jar-project.jar(目标目录结构)
│ pom.xml
│
└─src
└─main
├─java
└─resources -> /
│ file1.xml file1.xml
│ file2.xml file2.xml
│
└─META-INF -> /META-INF
└─autoconf -> /META-INF/autoconf
auto-config.xml auto-config.xml
3、Common directory
directory
│ file1.xml
│ file2.xml
│
└─conf
auto-config.xml
auto-config
完整的properties
...
生成配置文件的指令
auto-config 命令
$ autoconfig
Detected system charset encoding: UTF-8
If your can't read the following text, specify correct one like this:
autoconfig -c mycharset
使用方法:autoconfig [可选参数] [目录名|包文件名]
可选参数:
-c,--charset 输入/输出编码字符集
-d,--include-descriptors
包含哪些配置描述文件,例如:conf/auto-config.xml,可使用*、**、?通配符,如有多项,用逗号分隔
-D,--exclude-descriptors 排除哪些配置描述文件,可使用*、**、?通配符,如有多项,用逗号分隔
-g,--gui 图形用户界面(交互模式)
-h,--help 显示帮助信息
-i,--interactive 交互模式:auto|on|off,默认为auto,无参数表示on
-I,--non-interactive 非交互模式,相当于--interactive=off
-n,--shared-props-name 共享的属性文件的名称
-o,--output 输出文件名或目录名
-P,--exclude-packages 排除哪些打包文件,可使用*、**、?通配符,如有多项,用逗号分隔
-p,--include-packages
包含哪些打包文件,例如:target/*.war,可使用*、**、?通配符,如有多项,用逗号分隔
-s,--shared-props 共享的属性文件URL列表,以逗号分隔
-T,--type 文件类型,例如:war, jar, ear等
-t,--text 文本用户界面(交互模式)
-u,--userprop 用户属性文件
-v,--verbose 显示更多信息
可执行 jar
- xml 引入
org.apache.maven.plugins
maven-assembly-plugin
2.5.5
com.xxg.Main
jar-with-dependencies
make-assembly
package
single
- 命令行执行
$ mvn package