我需要在Linux和MS-Windows平台上运行外部脚本.
exec-maven-plugin吗?我应该输入什么文件名<executable>....</executable>?
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>compile-jni</id>
<phase>compile</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>./compile-jni</executable>
<workingDirectory>${basedir}/src/main/cpp</workingDirectory>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)我在MakefileLinux/MS-Windows这两个平台上使用相同的功能
我的剧本compile-jni.bat:
call "%ProgramFiles(x86)%\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x86
bash -c "make"
Run Code Online (Sandbox Code Playgroud)
我的剧本compile-jni.sh:
#!/bin/sh
make
Run Code Online (Sandbox Code Playgroud)
两位同事提出了替代方案:
使用一个变量script.extension
的变化<executable>./compile-jni${script.extension}</executable>中pom.xml
,并在命令行中添加变量mvn compile -Dscript.extention=.bat
或者在调用maven之前设置Visual Studio环境变量:
call "C:\%ProgramFiles(x86)%\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x86
mvn compile #(the same script 'bash -c "make"' works on both platforms)
Run Code Online (Sandbox Code Playgroud)但在这两种解决方案中,Eclipse用户可能会被卡住......我仍然在寻找一种自动而优雅的解决方案......