maven:如何以独立于操作系统的方式加载tools.jar/classes.jar?

发布于 2024-11-13 05:13:31 字数 740 浏览 4 评论 0原文

我正在使用一个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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

也只是曾经 2024-11-20 05:13:31

您可以通过为 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

雪若未夕 2024-11-20 05:13:31

如何在 git 中处理它会很有趣,因为我共享 .idea 目录。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文