maven 如何执行ant呢?maven如何执行本地命令呢?
使用maven-antrun-plugin 插件
详情请参阅: http://maven.apache.org/plugins/maven-antrun-plugin/run-mojo.html
简易示例:
<
plugins
>
<
plugin
>
<
groupId
>org.apache.maven.plugins</
groupId
>
<
artifactId
>maven-antrun-plugin</
artifactId
>
<
version
>1.7</
version
>
<
executions
>
<
execution
>
<
phase
>process-resources</
phase
>
<
goals
>
<
goal
>run</
goal
>
</
goals
>
<
configuration
>
<
target
>
<
ant
antfile
=
"build.xml"
>
<
target
name
=
"package.njrf"
/>
</
ant
>
</
target
>
</
configuration
>
</
execution
>
</
executions
>
</
plugin
>
</
plugins
>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>2.1</version>
<dependencies>
<dependency>
<groupId>ant</groupId>
<artifactId>ant-junit</artifactId>
<version>1.7.1</version>
</dependency>
<!-- ...其它包依赖 -->
</dependencies>
<executions>
<execution>
<id>ant-test</id>
<phase>package</phase>
<configuration>
<tasks>
<!-- 下面可以传入一些Maven变量 -->
<property name="compile_classpath" refid="maven.compile.classpath"/>
<property name="runtime_classpath" refid="maven.runtime.classpath"/>
<property name="test_classpath" refid="maven.test.classpath"/>
<property name="plugin_classpath" refid="maven.plugin.classpath"/>
<ant antfile="${basedir}/build.xml"/>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- ... -->
<plugins>
</build>
pom.xml内容:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.kunlunsoft</groupId> <artifactId>check_same_content</artifactId> <version>0.02-SNAPSHOT</version> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> <scope>test</scope> </dependency> <dependency> <groupId>com.kunlunsoft</groupId> <artifactId>io0007-find_progess</artifactId> <version>0.0.6-SNAPSHOT</version> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <version>2.5</version> </dependency> </dependencies> <build> <plugins> <!-- 生成可执行的 jar 包 <plugin> <artifactId>maven-assembly-plugin</artifactId> <configuration> <appendAssemblyId>false</appendAssemblyId> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> <archive> <manifest> <mainClass>com.hw.main.CheckSameApp</mainClass> </manifest> </archive> </configuration> <executions> <execution> <id>make-assembly</id> <phase>package</phase> <goals> <goal>assembly</goal> </goals> </execution> </executions> </plugin> --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-source-plugin</artifactId> <version>2.2.1</version> <configuration> <!-- <finalName>${project.build.name}</finalName> --> <attach>true</attach> <encoding>${project.build.sourceEncoding}</encoding> </configuration> <executions> <execution> <!-- 在 compile 阶段执行 maven-source-plugin 插件的 jar --> <phase>compile</phase> <goals> <goal>jar</goal> </goals> </execution> </executions> </plugin> <plugin> <!-- 设置编码 --> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.6</source> <target>1.6</target> <encoding>UTF-8</encoding> </configuration> </plugin> <!-- 使用SureFire-Plugin进行单元测试及selenium集成测试 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.15</version> <configuration> <skip>true</skip> </configuration> <executions> <execution> <id>run-test</id> <!-- 绑定到默认生命周期 --> <phase>test</phase> <goals> <goal>test</goal> </goals> <configuration> <skip>false</skip> <includes> <include>**/UnitTest.java</include> </includes> </configuration> </execution> <execution> <!-- 绑定到默认生命周期 --> <phase>integration-test</phase> <goals> <goal>test</goal> </goals> <configuration> <skip>false</skip> <includes> <include>**/IntegrationTest.java</include> </includes> </configuration> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-antrun-plugin</artifactId> <version>1.7</version> <configuration> <target name="abc"> <!-- <exec dir="." executable="Q:/work/apache-tomcat-7.0.41/bin/startup.bat" failοnerrοr="true"> </exec> --> <echo message="os is abc" /> </target> </configuration> <executions> <execution> <id>fds</id> <phase>clean</phase> <configuration> <tasks> <!-- <exec dir="${tomcat.home}/bin" executable="startup.bat" failοnerrοr="true"> </exec> --> <echo message="os is b2" /> </tasks> </configuration> <goals> <goal>run</goal> </goals> </execution> </executions> <dependencies> <dependency> <groupId>ant</groupId> <artifactId>ant-junit</artifactId> <version>1.6.2</version> </dependency> </dependencies> </plugin> </plugins> </build> </project>
打开命令行,执行 mvn clean ,运行结果(部分):
[INFO] Executing tasks
main:
[echo] os is b2
[INFO] Executed tasks
执行 mvn antrun:run ,运行结果:
[INFO] Executing tasks
abc:
[echo] os is abc