我想将JDK tools.jar作为编译依赖项。我发现了一些指示使用systemPath属性的示例,如下所示:
<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。
我正在寻找一种定义maven属性的方法,以便如果将系统检测为Mac Os X,则将值设置为$ {java.home} /../ Classes / classes.jar,否则将其设置为$ {java.home} /../ lib / tools.jar(就像可以使用ANT一样)。有人有主意吗?
感谢您向我介绍Maven个人资料。
我已经使用了如上所述的配置文件,并根据所需文件的存在来激活配置文件:
<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>
我在前一篇文章中发布了此答案以强调一个错误:属性部分只能在激活部分中使用,以便基于指定属性的存在来激活配置文件。为了定义属性,必须像上面一样使用properties部分。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句