我需要在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>
我为Linux / MS-Windows平台使用相同的Makefile
我的脚本compile-jni.bat:
call "%ProgramFiles(x86)%\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x86 bash -c "make"
我的脚本compile-jni.sh:
#!/bin/sh make
更新:
两位同事建议选择:
>使用变量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)
最后,我混合了想法=> < profile>用于根据操作系统设置内部变量script.extension:
<profiles> <profile> <id>Windows</id> <activation> <os> <family>Windows</family> </os> </activation> <properties> <script.extension>.bat</script.extension> </properties> </profile> <profile> <id>unix</id> <activation> <os> <family>unix</family> </os> </activation> <properties> <script.extension>.sh</script.extension> </properties> </profile> </profiles>
然后我使用该变量来完成脚本文件名:
<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${script.extension}</executable> </configuration> </execution> </executions> </plugin>
我将工作目录从pom.xml移动到了shell脚本.为了简化维护,常见的东西在这个外壳中移动.因此,批处理文件使用此shell脚本:
编译jni.bat:
call "%ProgramFiles(x86)%\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x86 bash compile-jni.sh
compile-jni.sh:
#!/bin/sh cd src/main/cpp make