0
我有一个.bat
文件,它执行我的Maven项目的构建的一些先决条件,并且我想在我开发的项目被构建时自动执行这个.bat
文件。有没有办法从maven配置执行批处理文件?
有什么办法可以用Maven执行这个任务吗?
我看到了另一个类似的问题,但它并没有解决我的问题。
我有一个.bat
文件,它执行我的Maven项目的构建的一些先决条件,并且我想在我开发的项目被构建时自动执行这个.bat
文件。有没有办法从maven配置执行批处理文件?
有什么办法可以用Maven执行这个任务吗?
我看到了另一个类似的问题,但它并没有解决我的问题。
执行批处理文件作为Maven构建过程的一部分的最直接和灵活的方法是使用maven-antrun-plugin和exec任务。例如,考虑下面的代码运行一个Windows可执行文件:
<!-- in the <build> section -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>sign</id>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<exec executable="${env.WIN7BASE}\bin\selfsign\inf2cat.exe">
<arg line="/drv:${project.build.directory}\classes /os:Vista_X86" />
</exec>
<exec executable="${signtool}">
<arg line="sign /v /a /t http://timestamp.verisign.com/scripts/timestamp.dll ${project.build.directory}\classes\${project.name}.cat" />
</exec>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
可能重复:http://stackoverflow.com/questions/3491937/i-want-to-execute-shell-commands-from-mavens- pom-xml –
我个人建议避免这样做。调用shell脚本使得maven构建不可移植。学习写一点MOJO,或切换到其他构建工具。 –
你可以使用'maven-antrun-plugin'并用ANT执行.bat文件。 – whyem