行家在Linux和Windows平台上调用外部脚本 [英] maven calls external script on both Linux and Windows platforms

查看:254
本文介绍了行家在Linux和Windows平台上调用外部脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在Linux和MS Windows平台上运行一个外部脚本。

I need to run an external script on both Linux and MS-Windows platforms.


  1. 请我用正确的插件 EXEC-Maven的插件

  2. 有没有更合适的插件?

  3. 我应该把什么文件名<可执行指令GT; ....< /可执行>

<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>


我用同样的的Makefile 这两个平台的Linux / MS-Windows系统

I use the same Makefile for both platforms Linux/MS-Windows

我的剧本编译jni.bat

My script compile-jni.bat:

call "%ProgramFiles(x86)%\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x86
bash -c "make" 

我的剧本 compile-jni.sh

My script compile-jni.sh:

#!/bin/sh
make

更新:

两位同事都建议选择:

UPDATE:

Two colleagues have suggested alternatives:


  1. 使用一个变量 script.extension
    变化&LT;可执行&GT; ./编译JNI $ {script.extension}&LT; /可执行&GT; 的pom.xml
    并追加命令行中的变量 MVN编译-Dscript.extention =蝙蝠

或调用的Maven之前设置Visual Studio环境变量:

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)


但在这两种解决方案,Eclipse用户可stucked ...我还在寻找一个自动和优雅的解决方案...

But on both solutions, Eclipse users may be stucked... I am still looking for an automatic and elegant solution...

推荐答案

最后,我是混合性的想法=>在&LT;曲线&GT; 用来设置一个内部变量 script.extension 取决于操作系统上:

Finally, I mixed the ideas => the <profiles> are used to set an internal variable script.extension depending on the operating system:

<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>

然后我使用变量来完成脚本文件:

Then I use the variable to complete the script filename:

<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脚本:

I have moved the working directory from the pom.xml to the shell script. In order to simplify maintenance, the common stuff is moved within this shell scrip. Therefore, the batch file use this shell script:

编译jni.bat

compile-jni.bat:

call "%ProgramFiles(x86)%\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x86
bash compile-jni.sh

compile-jni.sh

compile-jni.sh:

#!/bin/sh
cd src/main/cpp
make

这篇关于行家在Linux和Windows平台上调用外部脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆