我需要在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)
但是在这两个解决方案上,Eclipse用户可能会被卡住…我仍然在寻找一个自动优雅的解决方案…
最后,我混合了想法=> < 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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。