shell – maven在Linux和Windows平台上调用外部脚本
我需要在Linux和MS-Windows平台上运行外部脚本.
>我使用正确的插件exec-maven-plugin吗? <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.0VCvcvarsall.bat" x86 bash -c "make" 我的脚本compile-jni.sh: #!/bin/sh make 更新: 两位同事建议选择: >使用变量script.extension call "C:%ProgramFiles(x86)%Microsoft Visual Studio 10.0VCvcvarsall.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.0VCvcvarsall.bat" x86 bash compile-jni.sh compile-jni.sh: #!/bin/sh cd src/main/cpp make (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |