Lau*_*ent 73 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</systemPath>
</dependency>
Run Code Online (Sandbox Code Playgroud)
问题是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一样).有人有想法吗?
sbl*_*ndy 45
这就是配置文件的用途,提取属性的路径,设置窗口的配置文件,OSX等,并适当地定义属性值.
下面是讨论型材操作系统的文档页面:Maven的本地设置模式
它应该最终看起来像这样:
<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>
Run Code Online (Sandbox Code Playgroud)
Lau*_*ent 39
感谢您介绍我的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>
Run Code Online (Sandbox Code Playgroud)
我发布了这个答案,以突出显示上一篇文章中的错误:属性部分只能在激活部分中使用,以便根据指定属性的存在激活配置文件.要定义属性,必须像上面一样使用属性部分.
嗨,我知道你们都很聪明,但这让我花了几天时间才弄清楚答案是不完整的 - 个人资料和依赖性都是必要的.我希望没有人会再次浪费时间.请参阅下面的完整代码:
<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>
Run Code Online (Sandbox Code Playgroud)
不知何故,windows中的eclipse无法获取{java.home}.所以,我不得不设置JAVA_HOME而不是java.home.JAVA_HOME在Run-> Run Configurations-> Environment中设置.这对我来说是标准的JDK(不是Apple JDK).
<profiles>
<profile>
<id>windows-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}/../lib/tools.jar</exists>
</file>
</activation>
<properties>
<toolsjar>${java.home}/../lib/tools.jar</toolsjar>
</properties>
</profile>
</profiles>
<dependencies>
<dependency>
<groupId>jdk.tools</groupId>
<artifactId>jdk.tools</artifactId>
<version>jdk1.8.0</version>
<scope>system</scope>
<systemPath>${toolsjar}</systemPath>
</dependency>
</dependencies>
Run Code Online (Sandbox Code Playgroud)
我在 Q: Declare maven dependency on tools.jar 中找到了一个解决方案,以在 JDK 9 上工作
由于实际的 maven 巫术非常复杂,令新手感到惊讶并且是未来改进的主题,因此最好不要复制粘贴它。因此,此模块存在,因此您不必了解或关心细节。~~ https://github.com/olivergondza/maven-jdk-tools-wrapper
<dependency>
<groupId>com.github.olivergondza</groupId>
<artifactId>maven-jdk-tools-wrapper</artifactId>
<version>0.1</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
76604 次 |
| 最近记录: |