标签:
答:使用资源过滤功能,比如:
答: maven-svn-revision-number-plugin 可以从 SVN 中获取版本号,并将其变成环境变量,交由其他插件或者profile使用,详细帮助在这里 。一般和resource的filter机制同时使用
这段代码负责把resource文件中的内容替换成适当内容
有好几种方法都可以实现跳过单元测试步骤,一种是给mvn增加命令行参数 -Dmaven.test.skip=true 或者 -DskipTests=true ;另外一种是给surefire插件增加参数,如下:
<span class="kwrd"><</span><span class="html">project</span><span class="kwrd">></span> [...] <span class="kwrd"><</span><span class="html">build</span><span class="kwrd">></span> <span class="kwrd"><</span><span class="html">plugins</span><span class="kwrd">></span> <span class="kwrd"><</span><span class="html">plugin</span><span class="kwrd">></span> <span class="kwrd"><</span><span class="html">groupId</span><span class="kwrd">></span>org.apache.maven.plugins<span class="kwrd"></</span><span class="html">groupId</span><span class="kwrd">></span> <span class="kwrd"><</span><span class="html">artifactId</span><span class="kwrd">></span>maven-surefire-plugin<span class="kwrd"></</span><span class="html">artifactId</span><span class="kwrd">></span> <span class="kwrd"><</span><span class="html">version</span><span class="kwrd">></span>2.8<span class="kwrd"></</span><span class="html">version</span><span class="kwrd">></span> <span class="kwrd"><</span><span class="html">configuration</span><span class="kwrd">></span> <span class="kwrd"><</span><span class="html">skipTests</span><span class="kwrd">></span>true<span class="kwrd"></</span><span class="html">skipTests</span><span class="kwrd">></span> <span class="kwrd"></</span><span class="html">configuration</span><span class="kwrd">></span> <span class="kwrd"></</span><span class="html">plugin</span><span class="kwrd">></span> <span class="kwrd"></</span><span class="html">plugins</span><span class="kwrd">></span> <span class="kwrd"></</span><span class="html">build</span><span class="kwrd">></span> [...] <span class="kwrd"></</span><span class="html">project</span><span class="kwrd">></span>
可以,运行时候增加命令行参数 -Dtest=MyTest 即可,其中MyTest是所需要运行的单元测试用例名称,但是不需要包含package部分。
答:以下内容设定编译器编译java1.5的代码
答:指定source目录和test-source目录即可。
设置一个变量即可
{code:xml} <build> ... <plugin> <artifactId>maven-compiler-plugin</artifactId> <configuration> <encoding>UTF-8</encoding> </configuration> </plugin> ... </build> {code}
{code:xml} <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>native-maven-plugin</artifactId> <extensions>true</extensions> <configuration> </plugin> {code}
{code:xml} <project> [...] <build> <plugins> <plugin> <artifactId>maven-assembly-plugin</artifactId> <configuration> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> </configuration> </plugin> </plugins> </build> [...] </project> {code}
mvn assembly:assembly
{code:xml} <build> ... <resources> <resource> <filtering>true</filtering> <directory>src/main/command</directory> <includes> <include>run.bat</include> <include>run.sh</include> </includes> <targetPath>/abc</targetPath> </resource> <resource> <directory>src/main/scripts</directory> </resource> </resources> ... </build> {code}
{code:xml} <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>build-helper-maven-plugin</artifactId> <version>1.1</version> <executions> <execution> <id>add-source</id> <phase>generate-sources</phase> <goals> <goal>add-source</goal> </goals> <configuration> <sources> <source>src/config/java</source> <source>src/main/java</source> <source>src/member/java</source> </sources> </configuration> </execution> </executions> </plugin> {code}
{code:xml} <build> <sourceDirectory>http://www.cnblogs.com/src/java</sourceDirectory> <plugins> <plugin> <groupId>com.sun.enterprise</groupId> <artifactId>hk2-maven-plugin</artifactId> <configuration> <includes> <include>com/sun/logging/LogDomains.*</include> <include>com/sun/enterprise/util/OS.java</include> <include>com/sun/enterprise/util/io/FileUtils.java</include> <include>com/sun/enterprise/util/zip/**</include> <include>com/sun/enterprise/util/i18n/**</include> <include>com/sun/enterprise/deployment/backend/IASDeploymentException.java</include> </includes> <excludes> <exclude>com/sun/enterprise/config/ConfigBeansFactory.java</exclude> <exclude>com/sun/enterprise/config/clientbeans/**</exclude> </excludes> </configuration> </plugin> </plugins> <resources> <resource> <directory>http://www.cnblogs.com/src/java</directory> <includes> <include>**/*.properties</include> </includes> </resource> </resources> </build> {code}
{code:xml} <build> <sourceDirectory>src/java</sourceDirectory> <plugins> <plugin> <groupId>com.sun.enterprise</groupId> <artifactId>hk2-maven-plugin</artifactId> </plugin> </plugins> </build> {code}
hibernate3-maven-plugin,按照如下配置:
{code:xml} <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>hibernate3-maven-plugin</artifactId> <version>2.1</version> <configuration> <components> <component> <name>hbm2ddl</name> <implementation>annotationconfiguration</implementation> </component> </components> </configuration> <dependencies> <dependency> <groupId>hsqldb</groupId> <artifactId>hsqldb</artifactId> <version>${hsqldb.version}</version> </dependency> </dependencies> </plugin> {code}
答:当然可以,你可以使用插件 Tycho,详细内容可以参考这里[http://mattiasholmqvist.se/2010/02/building-with-tycho-part-1-osgi-bundles/].
<plugin> <groupid>org.sonatype.tycho</groupid> <artifactid>target-platform-configuration</artifactid> <version>0.7.0</version> <configuration> <resolver>p2</resolver> </configuration> </plugin> 另外,老牌的pde-maven-plugin就不要用了,已经好几年没见更新了。
使用专门的antrun插件,并且在target标签内部加入ant的代码
<span class="kwrd"><</span><span class="html">plugin</span><span class="kwrd">></span> <span class="kwrd"><</span><span class="html">artifactId</span><span class="kwrd">></span>maven-antrun-plugin<span class="kwrd"></</span><span class="html">artifactId</span><span class="kwrd">></span> <span class="kwrd"><</span><span class="html">version</span><span class="kwrd">></span>1.6<span class="kwrd"></</span><span class="html">version</span><span class="kwrd">></span> <span class="kwrd"><</span><span class="html">executions</span><span class="kwrd">></span> <span class="kwrd"><</span><span class="html">execution</span><span class="kwrd">></span> <span class="kwrd"><</span><span class="html">phase</span><span class="kwrd">></span> <span class="rem"><!-- 生命周期阶段 --></span> <span class="kwrd"></</span><span class="html">phase</span><span class="kwrd">></span> <span class="kwrd"><</span><span class="html">configuration</span><span class="kwrd">></span> <span class="kwrd"><</span><span class="html">target</span><span class="kwrd">></span> <span class="rem"><!-- 加入target内部的代码 --></span> <span class="kwrd"></</span><span class="html">target</span><span class="kwrd">></span> <span class="kwrd"></</span><span class="html">configuration</span><span class="kwrd">></span> <span class="kwrd"><</span><span class="html">goals</span><span class="kwrd">></span> <span class="kwrd"><</span><span class="html">goal</span><span class="kwrd">></span>run<span class="kwrd"></</span><span class="html">goal</span><span class="kwrd">></span> <span class="kwrd"></</span><span class="html">goals</span><span class="kwrd">></span> <span class="kwrd"></</span><span class="html">execution</span><span class="kwrd">></span> <span class="kwrd"></</span><span class="html">executions</span><span class="kwrd">></span> <span class="kwrd"></</span><span class="html">plugin</span><span class="kwrd">></span>
2)如何在ant脚本中引用maven的classpath?
maven给每一个依赖都生成了一个属性,格式为"groupId:artifactId[:classifier]:type",比如,如果一下例子就显示依赖的org.apache.common-util的jar文件路径
<span class="kwrd"><</span><span class="html">echo</span> <span class="attr">message</span><span class="kwrd">="Dependency JAR Path: ${org.apache:common-util:jar}"</span><span class="kwrd">/></span>
另外,maven还预定义了四个classpath的引用,他们是
3)如何使用antrun插件运行外部的build文件?
很简单,直接在antrun里边使用ant指令即可,如下:
<span class="kwrd"><</span><span class="html">plugin</span><span class="kwrd">></span> <span class="kwrd"><</span><span class="html">groupId</span><span class="kwrd">></span>org.apache.maven.plugins<span class="kwrd"></</span><span class="html">groupId</span><span class="kwrd">></span> <span class="kwrd"><</span><span class="html">artifactId</span><span class="kwrd">></span>maven-antrun-plugin<span class="kwrd"></</span><span class="html">artifactId</span><span class="kwrd">></span> <span class="kwrd"><</span><span class="html">version</span><span class="kwrd">></span>1.6<span class="kwrd"></</span><span class="html">version</span><span class="kwrd">></span> <span class="kwrd"><</span><span class="html">executions</span><span class="kwrd">></span> <span class="kwrd"><</span><span class="html">execution</span><span class="kwrd">></span> <span class="kwrd"><</span><span class="html">id</span><span class="kwrd">></span>compile<span class="kwrd"></</span><span class="html">id</span><span class="kwrd">></span> <span class="kwrd"><</span><span class="html">phase</span><span class="kwrd">></span>compile<span class="kwrd"></</span><span class="html">phase</span><span class="kwrd">></span> <span class="kwrd"><</span><span class="html">configuration</span><span class="kwrd">></span> <span class="kwrd"><</span><span class="html">target</span><span class="kwrd">></span> <span class="rem"><!-- 同时传递内置的classpath给外部ant文件 --></span> <span class="kwrd"><</span><span class="html">property</span> <span class="attr">name</span><span class="kwrd">="compile_classpath"</span> <span class="attr">refid</span><span class="kwrd">="maven.compile.classpath"</span><span class="kwrd">/></span> <span class="kwrd"><</span><span class="html">property</span> <span class="attr">name</span><span class="kwrd">="runtime_classpath"</span> <span class="attr">refid</span><span class="kwrd">="maven.runtime.classpath"</span><span class="kwrd">/></span> <span class="kwrd"><</span><span class="html">property</span> <span class="attr">name</span><span class="kwrd">="test_classpath"</span> <span class="attr">refid</span><span class="kwrd">="maven.test.classpath"</span><span class="kwrd">/></span> <span class="kwrd"><</span><span class="html">property</span> <span class="attr">name</span><span class="kwrd">="plugin_classpath"</span> <span class="attr">refid</span><span class="kwrd">="maven.plugin.classpath"</span><span class="kwrd">/></span> <span class="kwrd"><</span><span class="html">ant</span> <span class="attr">antfile</span><span class="kwrd">="${basedir}/build.xml"</span><span class="kwrd">></span> <span class="kwrd"><</span><span class="html">target</span> <span class="attr">name</span><span class="kwrd">="test"</span><span class="kwrd">/></span> <span class="kwrd"></</span><span class="html">ant</span><span class="kwrd">></span> <span class="kwrd"></</span><span class="html">target</span><span class="kwrd">></span> <span class="kwrd"></</span><span class="html">configuration</span><span class="kwrd">></span> <span class="kwrd"><</span><span class="html">goals</span><span class="kwrd">></span> <span class="kwrd"><</span><span class="html">goal</span><span class="kwrd">></span>run<span class="kwrd"></</span><span class="html">goal</span><span class="kwrd">></span> <span class="kwrd"></</span><span class="html">goals</span><span class="kwrd">></span> <span class="kwrd"></</span><span class="html">execution</span><span class="kwrd">></span> <span class="kwrd"></</span><span class="html">executions</span><span class="kwrd">></span> <span class="kwrd"></</span><span class="html">plugin</span><span class="kwrd">></span>
<skip>true</skip>
{code:xml} <project> [...] <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <testFailureIgnore>true</testFailureIgnore> </configuration> </plugin> </plugins> </build> [...] </project> {code}
reporting节点中加入则在
mvn site中执行,如果在
build节点中加入,则在build的时候自动运行检查。详细配置参考[pmd插件使用说明|http://maven.apache.org/plugins/maven-pmd-plugin/]
{code:xml} <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-pmd-plugin</artifactId> <version>2.5</version> </plugin> </plugins> {code}加入 checkstyle 检查,详细配置参考[checkstyle插件使用说明|http://maven.apache.org/plugins/maven-checkstyle-plugin/],同样注意放置在reporting和build节点中的区别(所有报表类插件都要同样注意):
{code:xml} <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-checkstyle-plugin</artifactId> <version>2.5</version> </plugin> {code}加入 simian 的支持,simian是一个支持代码相似度检查的工具,目前有maven插件,也有checkstyle的插件。它不仅可以检查java,甚至可以支持文本文件的检查。详细帮助信息参考[这里|http://www.redhillconsulting.com.au/products/simian/]。simian 的 maven插件在[这里|http://mojo.codehaus.org/simian-report-maven-plugin/introduction.html]
{code:xml} <build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>simian-maven-plugin</artifactId> <version>1.6.1</version> </plugin> </plugins> ... </build> {code}加入 jdepend 检查,详细配置参考[jdepend使用说明|http://mojo.codehaus.org/jdepend-maven-plugin/],
{code:xml} <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>jdepend-maven-plugin</artifactId> <version>2.0-beta-2</version> </plugin> {code}加入 findbugz 检查,详细配置参考[findbugz使用说明|http://mojo.codehaus.org/findbugs-maven-plugin/usage.html],
{code:xml} <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>findbugs-maven-plugin</artifactId> <version>2.0.1</version> </plugin> {code}加入javadoc生成,详细配置参考[javadoc usage|http://maven.apache.org/plugins/maven-javadoc-plugin/usage.html]
{code:xml} <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-javadoc-plugin</artifactId> <version>2.7</version> <configuration> ... </configuration> </plugin> {code}加入 jxr 支持,JXR是一个生成java代码交叉引用和源代码的html格式的工具,详细配置信息参考[jxr usage|http://maven.apache.org/plugins/maven-jxr-plugin/]。注意,jxr没有必要在build阶段运行。
{code:xml} <reporting> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jxr-plugin</artifactId> <version>2.1</version> </plugin> </plugins> </reporting> {code}加入 Cobertura 支持,它是一个代码覆盖率工具,可以用来评估具有相应测试的源代码的比率。详细帮助在[这里|http://mojo.codehaus.org/cobertura-maven-plugin/index.html]。另外一个功能相似的软件是[EMMA|http://emma.sourceforge.net/samples.html],详细的帮助在[这里|http://mojo.codehaus.org/emma-maven-plugin/usage.html]。两个产品的比较文章在[这里|http://www.topcoder.com/tc?module=Static&d1=features&d2=030107],个人倾向于都要用,因为给出的指标不一样,都有参考作用。
{code:xml|title=Cobertura } <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>cobertura-maven-plugin</artifactId> <version>2.4</version> <configuration> <check> <branchRate>85</branchRate> <lineRate>85</lineRate> <haltOnFailure>true</haltOnFailure> <totalBranchRate>85</totalBranchRate> <totalLineRate>85</totalLineRate> <packageLineRate>85</packageLineRate> <packageBranchRate>85</packageBranchRate> <regexes> <regex> <pattern>com.example.reallyimportant.*</pattern> <branchRate>90</branchRate> <lineRate>80</lineRate> </regex> <regex> <pattern>com.example.boringcode.*</pattern> <branchRate>40</branchRate> <lineRate>30</lineRate> </regex> </regexes> </check> </configuration> <executions> <execution> <goals> <goal>clean</goal> <goal>check</goal> </goals> </execution> </executions> </plugin> {code}
{code:xml|title=EMMA} <reporting> ... <plugins> ... <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>emma-maven-plugin</artifactId> <version>1.0-alpha-3-SNAPSHOT</version> </plugin> ... </plugins> ... </reporting> {code}添加 javaNCSS 插件,它是一个java代码的度量工具,详细参考在[这里|http://mojo.codehaus.org/javancss-maven-plugin/]。
{code:xml} <reporting> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>javancss-maven-plugin</artifactId> <version>2.0-beta-2</version> </plugin> </plugins> </reporting> {code}h4. profile相关
{code:xml} <activation> <property> <name>!environment.type</name> </property> </activation> {code}h4. 部署相关
{code:xml} <distributionManagement> <repository> <id>proficio-repository<id> <name>Proficio Repository<name> <url>file://${basedir}/target/deploy<url> <repository> <distributionManagement> {code}*# 使用ssh2配置
{code:xml} <distributionManagement> <repository> <id>proficio-repository<id> <name>Proficio Repository<name> <url>scp://sshserver.yourcompany.com/deploy<url> <repository> <distributionManagement> {code}*# 使用sftp配置
{code:xml} <distributionManagement> <repository> <id>proficio-repositoryi<d> <name>Proficio Repository<name> <url>sftp://ftpserver.yourcompany.com/deploy<url> <repository> <distributionManagement> {code}*# 使用外在的ssh配置编译扩展用于指定使用wagon外在ssh提供,用于提供你的文件到相应的远程服务器。
{code:xml} <distributionManagement> <repository> <id>proficio-repository<id> <name>Proficio Repository<name> <url>scpexe://sshserver.yourcompany.com/deploy<url> <repository> <distributionManagement> <build> <extensions> <extension> <groupId>org.apache.maven.wagon<groupId> <artifactId>wagon-ssh-external<artifactId> <version>1.0-alpha-6<version> <extension> <extensions> <build> {code}*# 使用ftp配置
{code:xml} <distributionManagement> <repository> <id>proficio-repository<id> <name>Proficio Repository<name> <url>ftp://ftpserver.yourcompany.com/deploy<url> <repository> <distributionManagement> <build> <extensions> <extension> <groupId>org.apache.maven.wagongroupId> <artifactId>wagon-ftpartifactId> <version>1.0-alpha-6version> <extension> <extensions> <build> {code}{panel} h4. 插件配置
{code:xml} ... <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-site-plugin</artifactId> <version>2.0-beta-6</version> <configuration> <outputEncoding>UTF-8</outputEncoding> </configuration> </plugin> ... {code}
本文借鉴与http://aiape.iteye.com/blog/1455420
版权声明:欢迎转载,希望在你转载的同时,添加原文地址,谢谢配合
标签:
原文地址:http://blog.csdn.net/u011225629/article/details/46989099