JDK tools.jar作为Maven依赖项

洛朗:

我想将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] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

使用Eclipse / Maven构建Hadoop-缺少工件jdk.tools:jdk.tools:jar:1.6

javax.tools是否依赖JDK?

使用java -jar将spring.boot与tools.jar作为依赖项运行

IntelliJ JDK 16抢先体验-是否成功?tools.jar

无法在 Ubuntu 的 JDK 中找到 tools.jar

在Java项目的pom.xml中,我丢失了工件jdk.tools:jdk.tools:jar:1.6错误

由于缺少工件jdk.tools:jar,使用maven的hadoop-common构建失败

在JDK中找不到Mule的Maven安装错误com.sun.tools.jar

Gradle JRE vs JDK,请从您的JDK中添加lib / tools.jar

泊坞窗:JAVA:OpenJDK的-8-jdk的高山图像丢失的javac和的tools.jar

STS中的简单Ant构建找不到jdk1.7.0_11 / lib / tools.jar

您需要使用JDK运行构建或在类路径上具有tools.jar

Ant + Vista 64:“无法找到tools.jar”(jre / jdk冲突?)

取决于Eclipse中tools.jar(Sun JDK)中的com.sun.javadoc

如何在不使用JDK的情况下从tools.jar使用JavaCompiler

当Hibernate Tools是Maven依赖项时,如何从Ant执行HibernateToolTask

使用Jar作为intelliJ / Maven依赖项

Maven项目对JDK版本的依赖

无法解析外部依赖 com.android.tools:desugar_jdk_libs:1.0.9 因为没有定义存储库

具有Maven依赖关系的构建路径问题(jconsole-jdk.jar)

找不到 tools.jar。请检查 /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home 是否包含有效的 JDK 安装

Maven找不到tools.jar

無法使用 Maven 3.8 編譯 JDK 17:錯誤:模塊 jdk.compiler 不會“打開 com.sun.tools.javac.processing”到未命名的模塊

JDK作为Windows的存档

我需要什么来构建JDK 9项目,使用Maven非模块化的依赖

JDK9自动模块和“拆分包”依赖项

jar作为jboss模块:依赖项

Spring-将application.properties注入jar(作为Maven依赖项)

hibernate-tools maven依赖导致超时扫描注释