maven: How to load tools.jar/classes.jar in an OS independent way?

≯℡__Kan透↙ 提交于 2019-12-10 11:38:02

问题


I am using a maven plugin that requires a class that is contained in the jdk's (windows) tools.jar (mac it's in classes.jar).

I add this as an explicit dependency of the plugin as follows:

<dependencies>
   <dependency>
     <groupId>sun.jdk</groupId>
     <artifactId>classes</artifactId>
     <version>1.6.0</version>
     <scope>system</scope>
     <systemPath>${java.home}/../Classes/classes.jar</systemPath>
   </dependency>
</dependencies>

This works if I'm using OS X. However, it does not work if I'm developing on a Windows machine. Moreover, I dislike the use of ../Classes.

Is there perhaps a better way to load in the JDK provided classes?

note: I understand the default (Sun, now Oracle) is to ship the JDK with these classes in lib/tools.jar and that the only real outlier is those who develop using the repackaged Apple JDK. Be that as it may, I am still interested in a -system independent approach- that does not depend so much on the specific path.


回答1:


You can achieve this by defining different build profiles for Windows VS Mac OS. See here for more details. http://maven.apache.org/guides/introduction/introduction-to-profiles.html




回答2:


It will be interesting how to deal with it in git, because I share .idea dir.



来源:https://stackoverflow.com/questions/6219533/maven-how-to-load-tools-jar-classes-jar-in-an-os-independent-way

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!