Monday, August 8, 2011

Maven dependency for tools.jar in JDK7

Although it has been known for sometime now that JDK7 will bring the change to vendor properties name change from “Sun Microsystems Inc.” to “Oracle Corporation”, I thought it would serve as a good reminder since Java 7 final was just released.

If you have a maven project that uses tools.jar and adds that as a dependency to the project as follows:

...
<profiles>
<profile>
<id>default-tools.jar</id>
<activation>
<property>
<name>java.vendor</name>
<value>Sun Microsystems Inc.</value>
</property>
</activation>
<dependencies>
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.4.2</version>
<scope>system</scope>
<systemPath>${java.home}/../lib/tools.jar</systemPath>
</dependency>
</dependencies>
</profile>
</profiles>
...

For making this work with JDK 7, you have to change the java.vendor value to Oracle Corporation like this:

...
<profiles>
<profile>
<id>default-tools.jar</id>
<activation>
<property>
<name>java.vendor</name>
<value>Oracle Corporation</value>
</property>
</activation>
<dependencies>
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.4.2</version>
<scope>system</scope>
<systemPath>${java.home}/../lib/tools.jar</systemPath>
</dependency>
</dependencies>
</profile>
</profiles>
...

4 comments:

Anonymous said...

Thank you for the post. Helped build an application on JDK7

Anonymous said...

In what file do you put this text? I've tried settings.xml and the projects pom.xml with no luck.

Saptarshi Purkayastha said...

You have to edit/add to your project's pom.xml, if you wish to use tools.jar in your project. The difference is using Sun (JDK6) or Oracle (JDK7)

JTheRocker said...

Awesome!!! it indirectly helped solved a problem for which I have been struggling since morning.