maven-anturn-plugin插件使用

maven-anturn-plugin插件为maven提供了ant功能,它可以使旧项目的配置操作在新项目得以重用。

该插件主要有2中执行ant操作的方法:

1.直接在插件中配置编写,例如:

<plugin>
	<groupId>org.apache.maven.plugins</groupId>
	<artifactId>maven-antrun-plugin</artifactId>
	<version>1.7</version>
	<executions>
		<execution>
			<id>install</id>
			<phase>install</phase>
			<configuration>
				<target>
					<echo message="********************copy profile propertie file *************************" />
					<copy file="webContent/WEB-INF/temporary-lib/dhcc-user-bundle-1.0.7.jar"
						tofile="webContent/WEB-INF/lib/dhcc-user-bundle-1.0.7.jar"
						overwrite="true" />
				</target>
			</configuration>
			<goals>
				<goal>run</goal>
			</goals>
		</execution>
	</executions>
</plugin>
上面的操作在项目编译的时候,复制了webContent/WEB-INF/temporary-lib/dhcc-user-bundle-1.0.7.jar文件到webContent/WEB-INF/lib/dhcc-user-bundle-1.0.7.jar。


2.调用ant脚本,即build.xml文件,并执行,例如:

<plugin>
	<groupId>org.apache.maven.plugins</groupId>
	<artifactId>maven-antrun-plugin</artifactId>
	<version>1.7</version>
	<executions>
		<execution>
			<id>ant-magic</id>
			<phase>prepare-package</phase>
			<goals>
				<goal>run</goal>
			</goals>
			<configuration>
				<tasks>
					<property name="compile_classpath" refid="maven.compile.classpath" />
					<!-- <property name="outputDir" value="${project.build.outputDirectory}"/> 
					<property name="sourceDir" value="${project.build.sourceDirectory}" /> -->
					<ant antfile="${basedir}/build.xml" target="prepare-package-clean" />
				</tasks>
			</configuration>
		</execution>
		<execution>
			<id>ant-magic2</id>
			<phase>package</phase>
			<goals>
				<goal>run</goal>
			</goals>
			<configuration>
				<tasks>
					<property name="compile_classpath" refid="maven.compile.classpath" />
					<ant antfile="${basedir}/build.xml" target="package-clean" />
				</tasks>
			</configuration>
		</execution>
	</executions>
</plugin>

build.xml

<?xml version="1.0" encoding="UTF-8"?>
<project default="prepare-package-clean" basedir=".">
	<description>
		dhcc build file
	</description>

	<property name="srcDir" location="src/main/java" />
	<property name="webDir" location="webContent" />
	<property name="lib.dir" location="${webDir}/WEB-INF/lib" />

	<property name="distDir" location="${webDir}" />
	<property name="dist.lib" location="${distDir}/WEB-INF/lib" />
	<property name="dist.classes" location="${distDir}/WEB-INF/classes" />
	<property name="targetDir" location="${distDir}/target" />

	<target name="prepare-package-clean">
		<echo message="clean lib jar and class start====" />
		<delete dir="${dist.classes}" />
		<delete dir="${dist.lib}\" />
		<echo message="clean lib jar and class end====" />
	</target>
	<target name="package-clean">
		<echo message="clean jersey and jar and other  jar start =====" />
		<delete file="${dist.lib}\jersey-core-1.17.1.jar" />
		<delete file="${dist.lib}\jersey-server-1.17.1.jar" />
		<delete file="${dist.lib}\jersey-servlet-1.17.1.jar" />
		<delete file="${dist.lib}\javassist-3.11.0.GA.jar" />
		<delete file="${dist.lib}\xml-apis-1.0.b2.jar" />
		<delete file="${dist.lib}\jackson-core-asl-1.9.11.jar" />
		<delete file="${dist.lib}\jackson-mapper-asl-1.9.11.jar" />
		<delete file="${dist.lib}\c3p0-0.9.1.1.jar" />
		<delete file="${dist.lib}\commons-fileupload-1.3.jar" />
		<delete file="${dist.lib}\jersey-core-1.18.jar" />
		<delete file="${dist.lib}\jersey-server-1.18.jar" />
		<delete file="${dist.lib}\jersey-servlet-1.18.jar" />
		<delete file="${dist.lib}\javassist-3.11.0.GA.jar" />
		<echo message="clean jersey and jar and other  jar end =====" />
	</target>
	<target name="init" depends="prepare-package-clean">
		<tstamp />
		<echo message="distDir ${distDir}" />
		<echo message="dist.classes dir ${dist.classes}" />
		<echo message="dist.lib ${dist.lib}" />

	</target>

	<target name="compile" depends="init">
		<echo message="compile java ================== " />
		<echo message="dist.lib:${dist.lib}" />
		<mkdir dir="${dist.lib}" />
		<mkdir dir="${dist.classes}" />
		<javac encoding="utf-8" srcdir="${srcDir}" destdir="${dist.classes}" >
        	<classpath refid="classpath"/>
		</javac>
	</target>

</project>


上面定义了2个节点(execution),分别在准备打包时执行prepare-package-clean任务,在打包的时候执行package-clean任务。

id:节点名

phase:任务执行时间,例如上面则是在执行maven package时运行任务

goal:只能为run,即运行时

configuration:任务配置

property:属性

echo:注释

ant:引入ant的脚本


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值