JDK tools.jar作为maven依赖

编程入门 行业动态 更新时间:2024-10-09 13:23:49
本文介绍了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依赖

本文发布于:2023-08-04 21:39:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1299855.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:tools   JDK   maven   jar

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!