maven:如何以独立于操作系统的方式加载tools.jar/classes.jar?
我正在使用一个maven插件,它需要一个包含在jdk(windows)tools.jar(mac它在classes.jar中)中的类。
我将其添加为插件的显式依赖项,如下所示:
<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>
如果我使用 OS X,则此方法有效。但是,如果我在 Windows 计算机上进行开发,则此方法不起作用。此外,我不喜欢使用 ../Classes。
是否有更好的方法来加载 JDK 提供的类?
注意:我知道默认情况(Sun,现在是 Oracle)是在 lib/tools.jar 中随这些类一起提供 JDK,唯一真正的异常值是那些使用重新打包的 Apple JDK 进行开发的人。尽管如此,我仍然对“独立于系统的方法”感兴趣,这种方法不太依赖于特定的路径。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以通过为 Windows 和 Mac OS 定义不同的构建配置文件来实现这一点。
请参阅此处了解更多详细信息。
http://maven.apache.org/guides/introduction/introduction-to -profiles.html
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
如何在 git 中处理它会很有趣,因为我共享 .idea 目录。
It will be interesting how to deal with it in git, because I share .idea dir.