maven和ant的完美结合案例。
1、加载 ant-contrib包
<profiles> <profile> <id>production</id> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-antrun-plugin</artifactId> <version>${maven-antrun-plugin.version}</version> <executions> <execution> <id>maven-ant</id> <phase>compile</phase> <goals> <goal>run</goal> </goals> <configuration> <tasks> <echo>settings.localRepository : ${settings.localRepository}</echo> <echo>project.build.outputDirectory : ${project.build.outputDirectory}</echo> <taskdef resource="net/sf/antcontrib/antlib.xml"> <classpath> <pathelement location="${settings.localRepository}/ant-contrib/ant-contrib/${ant-contrib.version}/ant-contrib-${ant-contrib.version}.jar" /> </classpath> </taskdef> </tasks> </configuration> </execution> </executions> </plugin> </plugins> </build> </profile> </profiles>
2、生产的log4j替代测试环境的log4j,并把配置文件移动到WEB-INF/classes。
Maven内置变量说明:
${basedir} 项目根目录
${project.build.directory} 构建目录,缺省为target
${project.build.outputDirectory} 构建过程输出目录,缺省为target/classes
${project.build.finalName} 产出物名称,缺省为${project.artifactId}-${project.version}
${project.packaging} 打包类型,缺省为jar
${project.xxx} 当前pom文件的任意节点的内容
<profiles> <profile> <id>production</id> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-antrun-plugin</artifactId> <version>${maven-antrun-plugin.version}</version> <executions> <execution> <phase>compile</phase> <goals> <goal>run</goal> </goals> <configuration> <tasks> <echo>Before log4j.properties move</echo> <move file="${project.build.outputDirectory}/log4j.production.properties" tofile="${project.build.outputDirectory}/log4j.properties" /> <echo>After log4j.properties move</echo> <echo>Begin conf move</echo> <copy todir="${project.build.outputDirectory}"> <fileset dir="${reb.target.dir}" /> </copy> <echo>After conf move</echo> </tasks> </configuration> </execution> </executions> </plugin> </plugins> </build> </profile> </profiles>