Most of us face this issue when they are working with Hadoop related source codes. Maven starts reporting a missing dependency.

Issue #

Missing artifact jdk.tools:jdk.tools:jar:1.6 in pom.xml and hence project would not build.

RCA #

The main reason behind this issue is that, the project depends in tools.jar which contains additional tools and utilities in JDK. These dependencies are not available in JRE without JDK. There is an issue with Maven plugin in Eclipse. Instead of using JRE which is set to build an individual project, Maven plugin uses JRE used by Eclipse.
In this case, eclipse was started with JRE which is without JDK and hence Maven could not located tools.jar

Solution #

Solution would be to start eclipse with JRE that is inside JDK. To do so, open eclipse.ini [OR sts.ini] and add following lines,
Please adjust path to javaw.exe as per necessity.

1
2
-vm
C:/jdk1.7.0_21/bin/javaw.exe

This might not work on all systems. If you encounter Java was started but returned exit code=1 error while starting the eclipse, modify the -vm argument to point to jvm.dll :
For Linux:

1
2
-vm
/opt/sun-jdk-1.6.0.02/bin/java

For MacOS:

1
2
-vm
/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home/bin/java

Paths can be different, please adjust accordingly.
If for some reason, you cannot edit ini file then you can modify the project pom.xml instead.
Add the following dependency to your pom file:[You should not add system specific dependencies in pom.xml though]

1
2
3
4
5
6
7
<dependency>
<groupId>jdk.tools</groupId>
<artifactId>jdk.tools</artifactId>
<scope>system</scope>
<systemPath>C:/Program Files/Java/jdk1.6.0_45/lib/tools.jar</systemPath>
<version>1.6</version>
</dependency>

Refresh the project along with Maven dependencies and you should be good to go.
You can simply build your project from command line Maven commands. It should still work.

References #

JDK files
Eclipse VM values
Eclipse Maven bug