I need to run an external script on both Linux and MS-Windows platforms.
- Do I use the right plugin
exec-maven-plugin
? - Is there a more suitable plugin?
What filename should I put in
<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>
I use the same Makefile
for both platforms Linux/MS-Windows
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
UPDATE:
Two colleagues have suggested alternatives:
Use a variable
script.extension
change<executable>./compile-jni${script.extension}</executable>
in thepom.xml
and append the variable within the command linemvn compile -Dscript.extention=.bat
or set the Visual Studio environment variables before calling maven:
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)
But on both solutions, Eclipse users may be stucked... I am still looking for an automatic and elegant solution...