Maven systemPath 未添加到运行时类路径

发布于 2024-10-05 10:09:36 字数 348 浏览 0 评论 0原文

我需要添加JDK的tools.jar作为项目依赖项。

将其设置为普通依赖项不起作用,因为将其安装到 Maven 存储库时,它会向 jar 文件添加版本号。此后,当我需要需要 tools.jar 位于类路径中的东西时,它会失败。

使用系统范围并使用 < 设置 jar 的路径系统路径>应该可以解决问题。然而,尽管在测试中 jar 被添加到类路径中,但在运行时却没有。

有办法解决这个问题吗?

顺便说一句,我添加了 < useManifestOnlyJar > false < /useManifestOnlyJar >到surefireplugin,以便我可以看到类路径中的每个文件。

I need to add JDK's tools.jar as a project dependency.

Setting it as a normal dependency is not working, because when installing it to the Maven repository, it adds a version number to the jar file. Thereafter, when I need something that needs tools.jar to be in the classpath, it fails.

Using the system scope and setting the path to the jar using < systemPath > should solve the problem. However, although in tests the jar is added to the classpath, at runtime it is not.

Is there a way around this?

Btw, I've added < useManifestOnlyJar >false< /useManifestOnlyJar > to the surefireplugin so that I can see every file in the classpath.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

无声情话 2024-10-12 10:09:36

Maven 是否在 JDK 中运行?

找出它正在运行的 Java 版本,

mvn-ver

将 JAVA_HOME 环境变量设置为指向 JDK。

Is Maven running in a JDK?

Find out what version of Java it's running,

mvn -ver

Set your JAVA_HOME env variable to point to a JDK.

潦草背影 2024-10-12 10:09:36

如果您的 JDK 中未包含它,请使用系统范围,请参阅常见问题解答

<profiles>
  <profile>
    <id>default-tools.jar</id>
    <activation>
      <property>
        <name>java.vendor</name>
        <value>Sun Microsystems Inc.</value>
      </property>
    </activation>
    <dependencies>
      <dependency>
        <groupId>com.sun</groupId>
        <artifactId>tools</artifactId>
        <version>1.4.2</version>
        <scope>system</scope>
        <systemPath>${java.home}/../lib/tools.jar</systemPath>
      </dependency>
    </dependencies>
  </profile>
</profiles>

if it is not included in your JDK, use system scope, see the FAQ

<profiles>
  <profile>
    <id>default-tools.jar</id>
    <activation>
      <property>
        <name>java.vendor</name>
        <value>Sun Microsystems Inc.</value>
      </property>
    </activation>
    <dependencies>
      <dependency>
        <groupId>com.sun</groupId>
        <artifactId>tools</artifactId>
        <version>1.4.2</version>
        <scope>system</scope>
        <systemPath>${java.home}/../lib/tools.jar</systemPath>
      </dependency>
    </dependencies>
  </profile>
</profiles>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文