我有一个 .bat
文件执行构建我的 Maven 项目的一些先决条件,我想在项目运行时自动执行这个 .bat
文件我开发的是内置的。
有什么方法可以用 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>
关于java - 有没有办法从 Maven 配置中执行批处理文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21855988/