如何使用Maven为特定操作系统构建jar? [英] how to build a jar with maven for a specific OS?

查看:221
本文介绍了如何使用Maven为特定操作系统构建jar?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用maven for Eclipse构建将在远程服务器上运行的jar.我的系统正在运行OS X,服务器正在运行CestOS. 对于项目,我需要 tensorflow库. Maven成功解决了依赖关系,因此我能够在本地运行项目.但是,在服务器上我收到错误消息,指出tensorflow库不存在,因为默认情况下maven仅包含macosx版本.在构建过程中如何强制Maven用Linux版本替代Tensorflow的macosx版本?

I am using maven for Eclipse to build a jar that will run on a remote server. My system is running OS X, the server is running CestOS. For the project I need tensorflow library. Maven successfully resolves dependencies so I am able to run the project locally. However, on the server I am getting error that tensorflow library is not there because by default maven includes only macosx version. How can I force maven to substitute macosx version of tensorflow by the linux version during build?

可以找到用于不同平台的TensorFlow Java库

TensorFlow java libraries for different platforms can be found here.

P.S.我已经尝试在pom中添加一个依赖项,并且系统范围指向jar.

P.S. I already tried adding a dependency in pom with the system scope pointing to jar.

推荐答案

从所链接页面上的jar名称来看,MacO和Linux版本之间的区别在于jar名称的version部分之后的文本

Judging by the jar names on the page you linked, the difference between the MacOs and Linux versions lies in the text after the version part on the jar name.

这称为classifier(请参见 Maven坐标)和是一个可选坐标,可在工件版本之后进行其他区分.

That is called the classifier (see Maven coordinates) and is an optional coordinate that gives an additional differentiation after the artifact version.

nandsito 所建议的,并扩展其答案,请尝试以下操作(未经测试,请告诉我,我会更新):

As already suggested by nandsito, and to expand on its answer, try this (untested, let me know and I'll update):

<profiles>
    <profile>
        <id>osx</id>

        <dependency>
            <groupId>org.bytedeco.javacpp-presets</groupId>
            <artifactId>tensorflow</artifactId>
            <version>0.9.0-1.2</version>
            <classifier>macosx-x86_64</classifier>
        </dependency>

    </profile>

    <profile>
        <id>linux</id>

        <dependency>
            <groupId>org.bytedeco.javacpp-presets</groupId>
            <artifactId>tensorflow</artifactId>
            <version>0.9.0-1.2</version>
            <classifier>linux-x86_64</classifier>
        </dependency>

    </profile>

</profiles>

并删除所有其他相关的<dependency>节点,这些节点都位于您的POM中(这样,如果没有<profiles>部分,就不会依赖tensorflow.)

And remove all the related <dependency> nodes elsewere in your POM (so that without the <profiles> part there would be no dependency for tensorflow).

此更改后,您每次都必须指定一个配置文件(因为POM中将没有tensorflow依赖性):在MacOs mvn clean package -Pmacos上准备软件包时以及在Centos mvn clean package -Plinux上准备软件包时

After this change you'll necessarily have to specify a profile each time (as there will be no tensorflow dependency in the POM): when preparing the package on MacOs mvn clean package -Pmacos and when preparing the package on Centos mvn clean package -Plinux

Eclipse允许您在Project properties> Maven下设置活动配置文件列表(您可以通过右键单击Project explorer中的项目文件夹来进入此窗口.

Eclipse allows you to set a list of active profiles under Project properties > Maven (you can get to this window by right-clicking on the project folder in the Project explorer.

这篇关于如何使用Maven为特定操作系统构建jar?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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