JDK tools.jar作为maven依赖 [英] JDK tools.jar as maven dependency

查看:342
本文介绍了JDK tools.jar作为maven依赖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将JDK tools.jar作为编译依赖项。我找到了一些示例,表明要使用 systemPath 属性,如下所示:

I would like to put JDK tools.jar as compile dependency. I found some examples that indicate to use the systemPath property like the following:

<dependency>
  <groupId>com.sun</groupId>
  <artifactId>tools</artifactId>
  <scope>system</scope>
  <systemPath>${java.home}/../lib/tools.jar</systemPath>
</dependency>

问题是Mac OS X的路径不正确(但是对于Windows和Linux的)。对于它,正确的路径是 $ {java.home} /../ Classes / classes.jar

The problem is that the path is not correct for Mac Os X (however it is correct for Windows and Linux). For it, the correct path is ${java.home}/../Classes/classes.jar.

我正在寻找一个为了定义maven属性,如果系统被检测为Mac Os X,则将值设置为 $ {java.home} /../ Classes / classes.jar ,否则设置为到$ {java.home} /../ lib / tools.jar (就像可以用ANT一样)。有人有想法吗?

I am looking for a way in order to define a maven property such that if system is detected as Mac Os X, value is set to ${java.home}/../Classes/classes.jar, otherwise it is set to ${java.home}/../lib/tools.jar (like it is possible to do with ANT). Does someone has an idea ?

推荐答案

感谢您介绍我的maven个人资料。

Thank you for introducing me maven profiles.

我使用了上面提到的配置文件,并根据所需文件的存在激活配置文件:

I have used profile as mentioned above and by activating a profile based on the presence of the desired file :

<profiles>
    <profile>
        <id>default-profile</id>
        <activation>
            <activeByDefault>true</activeByDefault>
            <file>
                <exists>${java.home}/../lib/tools.jar</exists>
            </file>
        </activation>
        <properties>
            <toolsjar>${java.home}/../lib/tools.jar</toolsjar>
        </properties>
    </profile>
    <profile>
        <id>mac-profile</id>
        <activation>
            <activeByDefault>false</activeByDefault>
            <file>
                <exists>${java.home}/../Classes/classes.jar</exists>
            </file>
        </activation>
        <properties>
            <toolsjar>${java.home}/../Classes/classes.jar</toolsjar>
        </properties>
    </profile>
</profiles>

我发布此答案以突出显示上一篇文章中的错误:属性部分只能用于激活部分,以便根据指定属性的存在激活配置文件。为了定义属性,必须像上面一样使用属性部分。

I posted this answer to highlight a mistake in the previous post : the property section can only be used in activation section in order to activate a profile based on the existence of the specified property. In order to define a property, the properties section must be used like above.

这篇关于JDK tools.jar作为maven依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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