加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

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

发布时间:2020-12-15 18:55:29 所属栏目:安全 来源:网络整理
导读:我需要在Linux和MS-Windows平台上运行外部脚本. 我使用正确的插件exec-maven-plugin吗? 有没有更合适的插件? 我应该输入什么文件名 executable …. / executablegt ;? plugin groupIdorg.codehaus.mojo/groupId artifactIdexec-maven-plugin/artifactId ve
我需要在Linux和MS-Windows平台上运行外部脚本.

>我使用正确的插件exec-maven-plugin吗?
有没有更合适的插件?
>我应该输入什么文件名< executable> ….< / executable&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>

我为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
更改< executable> ./ compile-jni ${script.extension}< / executable>在pom.xml中
并在命令行mvn compile -Dscript.extention = .bat附加变量
>或者在调用maven之前设置Visual Studio环境变量:

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读