我需要在Linux和MS-Windows平台上运行外部脚本。
编译插件是否有更合适的插件?
<executable>....</executable>
org.codehaus.mojo exec-maven-plugin 1.2.1 exec-maven-plugin
我在两个平台上使用相同的Makefile
My script compile-jni.bat
**:**
call "%ProgramFiles(x86)%\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x86
bash -c "make"
My script compile-jni.sh
**:**
#!/bin/sh
make
更新:
两位同事提出了替代方案:
pom.xml
中使用变量script.extension
<executable>./compile-jni${script.extension}</executable>
,并在命令行中附加该变量mvn compile -Dscript.extention=.bat
调用"C:\%ProgramFiles( x86 )%\Microsoft Visual Studio 10.0\VC\vcvarsall.bat“x86 mvn compile #(相同的脚本'bash -c "make"‘在两个平台上都有效)
但在这两种解决方案中,Eclipse用户可能会被卡住...我仍然在寻找一种自动而优雅的解决方案...
发布于 2013-02-11 18:32:51
运行sh脚本的示例。
这只是为sh脚本执行一个chmod
。请记住,如果您有一个sh脚本,那么在执行其他操作(如运行实际脚本)之前,您绝对应该执行一个chmod
,因此,以此为例,您可以执行下面的第一个<execution>
,并添加另一个<execution>
来运行您的脚本。
对于批处理文件,只能有一个<execution>
来运行脚本
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>${org.codehaus.mojo.version}</version>
<executions>
<execution>
<id>script-chmod</id>
<phase>install</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>chmod</executable>
<arguments>
<argument>+x</argument>
<argument>yourscript.sh</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
您可能希望根据您所在的计算机添加一个配置文件:
<profiles>
<profile>
<activation>
<os>
<family>!windows</family>
</os>
</activation>
<plugin>
<!-- add your exec-maven-plugin here -->
</plugin>
...
</profile>
</profiles>
希望这将是你所需要的东西的开始
https://stackoverflow.com/questions/14809931
复制相似问题