首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >maven在Linux和Windows平台上都调用外部脚本

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

Stack Overflow用户
提问于 2013-02-11 18:08:42
回答 1查看 29.7K关注 0票数 25

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

编译插件是否有更合适的插件?

  • 我应该在<executable>....</executable> org.codehaus.mojo exec-maven-plugin 1.2.1 exec-maven-plugin

  • Is -jni编译EXEC./-jni中输入什么文件名?/
  1. -jni${basedir}/src/main/cpp

我在两个平台上使用相同的Makefile

My script compile-jni.bat**:**

代码语言:javascript
复制
call "%ProgramFiles(x86)%\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x86
bash -c "make" 

My script compile-jni.sh**:**

代码语言:javascript
复制
#!/bin/sh
make

更新:

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

  1. pom.xml中使用变量script.extension <executable>./compile-jni${script.extension}</executable>,并在命令行中附加该变量mvn compile -Dscript.extention=.bat
  2. 或在调用maven之前设置Visual Studio环境变量:

调用"C:\%ProgramFiles( x86 )%\Microsoft Visual Studio 10.0\VC\vcvarsall.bat“x86 mvn compile #(相同的脚本'bash -c "make"‘在两个平台上都有效)

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

EN

回答 1

Stack Overflow用户

发布于 2013-02-11 18:32:51

运行sh脚本的示例。

这只是为sh脚本执行一个chmod。请记住,如果您有一个sh脚本,那么在执行其他操作(如运行实际脚本)之前,您绝对应该执行一个chmod,因此,以此为例,您可以执行下面的第一个<execution>,并添加另一个<execution>来运行您的脚本。

对于批处理文件,只能有一个<execution>来运行脚本

代码语言:javascript
复制
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>${org.codehaus.mojo.version}</version>
            <executions>
               <execution>
                    <id>script-chmod</id>
                    <phase>install</phase>
                    <goals>
                        <goal>exec</goal>
                    </goals>
                    <configuration>
                        <executable>chmod</executable>
                        <arguments>
                            <argument>+x</argument>
                            <argument>yourscript.sh</argument>
                        </arguments>
                    </configuration>
                </execution>
            </executions>
        </plugin>

您可能希望根据您所在的计算机添加一个配置文件:

代码语言:javascript
复制
<profiles>
  <profile>
    <activation>
      <os>
        <family>!windows</family>
      </os>
    </activation>
    <plugin>
      <!-- add your exec-maven-plugin here -->
    </plugin>
    ...
  </profile>
</profiles>

希望这将是你所需要的东西的开始

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14809931

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档