相关疑难解决方法(0)

maven在Linux和Windows平台上调用外部脚本

我需要在Linux和MS-Windows平台上运行外部脚本.

  1. 我使用正确的插件exec-maven-plugin吗?
  2. 有更合适的插件吗?
  3. 我应该输入什么文件名<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>
    
    Run Code Online (Sandbox Code Playgroud)

我在MakefileLinux/MS-Windows这两个平台上使用相同的功能

我的剧本compile-jni.bat:

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

我的剧本compile-jni.sh:

#!/bin/sh
make
Run Code Online (Sandbox Code Playgroud)

更新:

两位同事提出了替代方案:

  1. 使用一个变量script.extension 的变化<executable>./compile-jni${script.extension}</executable>pom.xml ,并在命令行中添加变量mvn compile -Dscript.extention=.bat

  2. 或者在调用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)
    
    Run Code Online (Sandbox Code Playgroud)

但在这两种解决方案中,Eclipse用户可能会被卡住......我仍然在寻找一种自动而优雅的解决方案......

shell batch-file pom.xml maven exec-maven-plugin

23
推荐指数
2
解决办法
3万
查看次数

标签 统计

batch-file ×1

exec-maven-plugin ×1

maven ×1

pom.xml ×1

shell ×1