maven-compiler-plugin
在pom.xml中没有声明的加入这个plugin时,是按照1.3来进行编译的。
可以在这个plugin中指定source和target的版本,当指定的版本是1.5,而用到的编译器确实jdk1.6时,即使源码中用到了JDK1.6库中的方法,照样可以编译通过。
当然,如果source中有泛型,设定版本为1.3,还是编译不过的。
这里source和target版本的含义应该是指定java虚拟机所能识别的版本号。
在上面这个case中,jdk1.6编译的,目标版本1.5编译后,在1.5的虚拟机上运行错误,提示所用1.6库中的方法不存在。
可如果编译目标版本是1.6,然后在1.5虚拟机上运行错误提示Bad version number in .class file。
所以,如果希望在1.5编译时就发现错误,就要用1.5的编译器。
可以在这个plugin中指定source和target的版本,当指定的版本是1.5,而用到的编译器确实jdk1.6时,即使源码中用到了JDK1.6库中的方法,照样可以编译通过。
当然,如果source中有泛型,设定版本为1.3,还是编译不过的。
这里source和target版本的含义应该是指定java虚拟机所能识别的版本号。
在上面这个case中,jdk1.6编译的,目标版本1.5编译后,在1.5的虚拟机上运行错误,提示所用1.6库中的方法不存在。
可如果编译目标版本是1.6,然后在1.5虚拟机上运行错误提示Bad version number in .class file。
所以,如果希望在1.5编译时就发现错误,就要用1.5的编译器。
maven-antrun-plugin
使用这个插件,只需要在项目的pom文件中定义如下插件片段:
- <plugin>
- <artifactId>maven-antrun-plugin</artifactId>
- <executions>
- <execution>
- <phase>compile</phase>
- <goals>
- <goal>run</goal>
- </goals>
- <configuration>
- <tasks>
- <delete file="${project.build.directory}/classes/abc.properties" />
- </tasks>
- </configuration>
- </execution>
- </executions>
- </plugin>
这里,我们在maven的编译阶段执行一些文件的删除操作,比如将测试环境的配置文件删除,复制生产环境的配置文件等等,我们都可以使用ant的task来定义。通过ant的maven插件,可以将ant的强大功能也都引入到maven中来,实现二者的强强结合。
参考文档:
1、maven-antrun-plugin插件:http://maven.apache.org/plugins/maven-antrun-plugin/
2、ant的task列表总览:http://ant.apache.org/manual/tasksoverview.html
maven-surefire-plugin
The Surefire Plugin is used during the test phase of the build lifecycle to execute the unit tests of an application. It generates reports in 2 different file formats:
- Plain text files (*.txt)
- XML files (*.xml)
By default, these files are generated at ${basedir}/target/surefire-reports.
Goals Overview
The Surefire Plugin has only 1 goal:
- surefire:test runs the unit tests of an application.
maven-eclipse-plugin
Maven Eclipse plugin是用来生成eclipse的project文件的,如(.classpath、.project等)。
maven-source-plugin
The Source Plugin creates a jar archive of the source files of the current project. The jar file is, by default, created in the project's target directory.
当使用一个普通的jar包时,集成环境(比如Eclipse)没有足够的信息用来显示类的javadoc,连接口参数的名称都会变成arg0,arg1等等这样的样式。为了显示javadoc,我们必须手工指定库的源码所在。而像我这么懒的程序员,怎么可能靠手工解决问题呢?
我们可以用Maven的source plugin来方便的解决这个问题。在编译jar包的时候,plugin可以编一个源码包。 把它部署到你的Maven源中,用Maven的eclipse plugin就可以直接将源码加到classpath并在集成环境使用了。
我们可以用Maven的source plugin来方便的解决这个问题。在编译jar包的时候,plugin可以编一个源码包。 把它部署到你的Maven源中,用Maven的eclipse plugin就可以直接将源码加到classpath并在集成环境使用了。