简体   繁体   English

在基于操作系统的Maven项目中包含一个Jar

[英]Include a Jar in Maven Project based on Operating System

I'm using a third party software in my Maven Project. 我在Maven项目中使用了第三方软件。 The API calls are same for both Windows and Mac OS but the JAR files are different. Windows和Mac OS的API调用相同,但JAR文件不同。 Is there a way to identify the operating system at run-time and load appropriate jar from my lib folder in a Maven Project ? 有没有一种方法可以在运行时识别操作系统并从Maven项目的lib文件夹中加载适当的jar? I want to be able to provide this final executable Jar to my client who may use my final Jar in an Windows or Mac OS and should be able to work on it by including my Jar in his project. 我希望能够将这个最终的可执行Jar提供给我的客户,后者可以在Windows或Mac OS中使用我的最终Jar,并且应该能够通过将Jar包含在他的项目中来对其进行处理。 For now, my client is including the Jar in his class path which seems as a horrible way of doing. 目前,我的客户正在将Jar包含在他的上课路径中,这似乎是一种可怕的做法。

It could be nicely done by using Maven profiles and activation feature 通过使用Maven配置文件和激活功能可以很好地完成

<profiles>
    <profile>
        <id>windows-x86_64</id>
        <activation>
            <os>
                <family>windows</family>
                <arch>amd64</arch>
            </os>
        </activation>            
    </profile>

    <profile>
        <id>windows-x86</id>
        <activation>
            <os>
                <family>windows</family>
                <arch>x86</arch>
            </os>
        </activation>
    </profile>

In this profiles you could set up custom properties, custom dependencies, etc. 在此配置文件中,您可以设置自定义属性,自定义依赖项等。

您可能需要Maven NAR插件,或者可能使用配置文件,具体取决于系统特定部分的实际内容

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM