Jdk Tools.Jar as Maven Dependency

JDK tools.jar as maven dependency

Thank you for introducing me maven profiles.

I have used profile as mentioned above and by activating a profile based on the presence of the desired file :

<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>

I posted this answer to highlight a mistake in the previous post : the property section can only be used in activation section in order to activate a profile based on the existence of the specified property. In order to define a property, the properties section must be used like above.

Problem when adding a dependency to maven

Interpretting the error message

Could not find artifact jdk.tools:jdk.tools:jar:1.6 at specified path
/usr/lib/jvm/java-11-openjdk-amd64/../lib/tools.jar

The tools.jar file is supplied by the JDK - looks like 1.6 is referenced from the included dependency - suggest you explicitly exclude it:

<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-jdbc</artifactId>
<version>3.1.2</version>
<exclusions>
<exclusion>
<artifactId>jdk.tools</artifactId>
<groupId>jdk.tools</groupId>
</exclusion>
</exclusions>

</dependency>

In the pom.xml for a java project, I get missing artifact jdk.tools:jdk.tools:jar:1.6 error

I finally tackled this the proper way.

This happens when eclipse is launched with the JRE instead of the JDK as tools.jar isn't in the JRE.
Based on that assertion, try installing the JDK. If it's already installed, check in your Path that you have the JDK path and not the JRE path.

Be careful, the latest versions of java seems to add in the Path the following directory: C:\ProgramData\Oracle\Java\javapath. It contains shortcuts that may link to the JRE. You'll want to remove that and add in the link to your JDK bin folder. (e.g. C:\Program Files\Java\jdk1.8.0_66\bin)

Note that you may need to restart your computer for the changes in the Path to be effective for the eclipse launch (I don't really understand why I had to but I did).

Also note that Java updates will probably re-add the javapath to your PATH. So you may want not to use auto-updates but instead manually update your JDK and adapt your path after the install. It's a bit heavy but does the work.



Related Topics



Leave a reply



Submit