Search code examples
javamavenmaven-2maven-3pom.xml

Maven : Missing artifact com.sun:tools:jar:1.6.0 compile time exception in POM.xml


I am getting one weird issue and getting a compile time exception in my pom.xml when i am trying to add dependancy for tools. jar displayed as below(Missing artifact com.sun:tools:jar:1.6.0)

Issue

I have set my JAVA_HOME variable as below:

JAVA_HOME: C:\Program Files\Java\jdk1.6.0_34

When i hardcode it to the actual path of JDK1.6 i dont find any error as below.

 <dependency>
   <groupId>com.sun</groupId>
   <artifactId>tools</artifactId>
   <version>1.6.0</version>
   <scope>system</scope>
   <systemPath>C:\Program Files\Java\jdk1.6.0_34\lib\tools.jar</systemPath>
 </dependency>

but i know its not good practise. Request guidance in resolving this error.


Solution

  • java.home is a System property which generally points to the jre directory and you are getting an error as you have pointed to a jar which doesn't exist.

    In case you want to refer to an environment variable within your pom file, use the below syntax.

    ${env.variable_name}
    

    In your case, it should be ${env.JAVA_HOME} as seen below

    <dependency>
       <groupId>com.sun</groupId>
       <artifactId>tools</artifactId>
       <version>1.6.0</version>
       <scope>system</scope>
       <systemPath>${env.JAVA_HOME}/lib/tools.jar</systemPath>
     </dependency>
    

    Update: As lexicore has mentioned, this wont work with MAC as the MAC JDK has a different file structure.