Java JDK tools.jar作为maven依赖项
我想将JDK tools.jar作为编译依赖项。我发现一些示例指示使用systemPath属性,如下所示:Java JDK tools.jar作为maven依赖项,java,maven-2,tools.jar,Java,Maven 2,Tools.jar,我想将JDK tools.jar作为编译依赖项。我发现一些示例指示使用systemPath属性,如下所示: <dependency> <groupId>com.sun</groupId> <artifactId>tools</artifactId> <scope>system</scope> <systemPath>${java.home}/../lib/tools.jar</s
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<scope>system</scope>
<systemPath>${java.home}/../lib/tools.jar</systemPath>
</dependency>
com.sun
工具
系统
${java.home}/./lib/tools.jar
问题是路径对于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一样)。有人有想法吗?这就是配置文件的用途,提取属性路径,为windows、OSX等设置配置文件,并适当定义属性值 以下是讨论操作系统配置文件的文档页面: 它最终应该是这样的:
<profiles>
<profile>
<id>windows_profile</id>
<activation>
<os>
<family>Windows</family>
</os>
</activation>
<properties>
<toolsjar>${java.home}/../lib/tools.jar</toolsjar>
</properties>
</profile>
<profile>
<id>osx_profile</id>
<activation>
<os>
<family>mac</family>
</os>
</activation>
<properties>
<toolsjar>${java.home}/../Classes/classes.jar</toolsjar>
</properties>
</profile>
</profiles>
windows\u配置文件
窗户
${java.home}/./lib/tools.jar
osx_剖面图
雨衣
${java.home}/./Classes/Classes.jar
感谢您为我介绍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>
默认配置文件
真的
${java.home}/./lib/tools.jar
${java.home}/./lib/tools.jar
mac配置文件
假的
${java.home}/./Classes/Classes.jar
${java.home}/./Classes/Classes.jar
我发布这个答案是为了强调上一篇文章中的一个错误:属性部分只能用于激活部分,以便根据指定属性的存在激活配置文件。要定义属性,必须像上面一样使用属性部分。我的解决方案:
$JAVA\u HOME/lib
$JAVA\u HOME/。
命名库中创建一个符号链接,目标将位于$JAVA\u HOME/lib
嗨,我知道你们都很聪明,但这让我花了几天时间才发现答案并不完整——个人资料和依赖性都是必要的。我希望没有人再在这件事上浪费时间。请参阅下面我的完整代码:
<profiles>
<profile>
<id>osx_profile</id>
<activation>
<activeByDefault>false</activeByDefault>
<os>
<family>mac</family>
</os>
</activation>
<properties>
<toolsjar>${java.home}/../Classes/classes.jar</toolsjar>
</properties>
<dependencies>
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.6.0</version>
<scope>system</scope>
<systemPath>${toolsjar}</systemPath>
</dependency>
</dependencies>
</profile>
</profiles>
osx_剖面图
假的
雨衣
${java.home}/./Classes/Classes.jar
com.sun
工具
1.6.0
系统
${toolsjar}
不知何故,windows中的eclipse无法获取{java.home}。因此,我必须将JAVA_设置为HOME而不是JAVA.HOME。JAVA_HOME是在运行->运行配置->环境中设置的。这对我来说适用于标准JDK(而不是苹果JDK)
windows配置文件
真的
${JAVA_HOME}/lib/tools.jar
${JAVA_HOME}/lib/tools.jar
mac配置文件
假的
${java.home}/./lib/tools.jar
${java.home}/./lib/tools.jar
jdk.tools
jdk.tools
jdk1.8.0
系统
${toolsjar}
的注释是正确的
您需要配置文件,并且需要依赖项
位于配置文件
块之外。
配置文件只确定将获得哪个值${toolsjar}
<dependencies>
<dependency>
<groupId>jdk.tools</groupId>
<artifactId>jdk.tools</artifactId>
<version>jdk1.8.0</version>
<scope>system</scope>
<systemPath>${toolsjar}</systemPath>
</dependency>
</dependencies>
jdk.tools
jdk.tools
jdk1.8.0
系统
${toolsjar}
我在Q中找到了一个解决方案:
由于实际的maven魔法相当复杂,让新手感到惊讶,并且是未来改进的主题,因此最好不要将其复制粘贴。因此,此模块存在,因此您不必知道或关心详细信息。~~
com.github.olivergondza
maven jdk工具包装器
0.1
适合初学者的正确说明
首先将此配置文件添加到标记上方的Pom.xml文件或其中的其他位置
<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>
默认配置文件
真的
${java.home}/./lib/tools.jar
${java.home}/./lib/tools.jar
mac配置文件
假的
${java.home}/./Classes/Classes.jar
${java.home}/./Classes/Classes.jar
然后纠正JRE路径
后藤:
Windows>首选项>已安装的JRE
选中intalled JRE并双击它,或从右菜单单击edit,然后确保JRE主路径位于JDK内,类似于:
C:\ProgramFiles\Java\jdk1.8.0\U 181\jre
如果您单独安装了JRE,那么eclipse会选择独立的JRE,如:
C:\Program Files\Java\jre1.8.0\u 181\
因此,将其更改为JDK附带的JRE:
C:\ProgramFiles\Java\jdk1.8.0\U 181\jre
这不是一个好的解决方案,因为它意味着在必须将JAR文件放在类路径中的每台机器上执行一些操作。我尝试了这个方法以及基于我在别处找到的解决方案的各种方法,但没有得到我预期的结果。classes.JAR存在性检查的好处是
<dependency>
<groupId>com.github.olivergondza</groupId>
<artifactId>maven-jdk-tools-wrapper</artifactId>
<version>0.1</version>
</dependency>
<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>