resolving tools.jar in ivy

1.8k views Asked by At

i have a project that uses ivy to manage its dependencies. i'm implementing a feature to the project that requires me to include tools.jar. however, because tools.jar is platform dependent, i'm trying to use ivy to resolve to a local file for the artifact. i'm doing the following:

<dependency org="com.sun" names="tools" rev="1.6.0">
  <artifact name="tools" type="jar" url="file:///${java.home}/../lib/tools.jar"/>
</dependency>

that should retrieve the file from the local ${java.home}/../lib/tools.jar. (note: java.home points to the JRE installation).

however, there are problems resolving the location. on my windows machine, it seems to think "c" is the protocol (c is coming from ${java.home}. and i'm sure that my url is defined correctly because "file:///C:/foo" is the correct way to specify a url to a file (3 slashes). the problem i see is that it strips off 2 slashes and tries "file:/C:..." instead of "file:///C:.." as i specify above. i also tried specifying the path to the file directly w/o the ${java.home}

i would like to keep this approach retrieving through ivy, but i can't get it to work. any ideas?

2

There are 2 answers

6
Mark O'Connor On

JAVA_HOME needs to point at the location of your JDK, not your JRE. Once you change this, ANT will stop complaining about a missing tools jar.

Looking at the path you provide above, I suspect that you already have a JDK installed....

Analysis

On my system the tools jar is located here:

$ find $JAVA_HOME -name tools.jar
/usr/lib/jvm/java-6-openjdk/lib/tools.jar

Oddly, and confusing, the Java JDK ships with a JRE inside

$ find $JAVA_HOME -name java
/usr/lib/jvm/java-6-openjdk/bin/java
/usr/lib/jvm/java-6-openjdk/jre/bin/java
1
krico On

I was able to get this to work using a dedicated resolver

ivysettings.xml

<resolvers>
  <!-- your other resolvers here -->
  <filesystem name="JDK" local="true">
    <artifact pattern="${java.home}/lib/[artifact].[type]" />
    <artifact pattern="${java.home}/../lib/[artifact].[type]" />
    <!-- You can add more patterns to fit your needs for MacOSX etc -->
  </filesystem>
</resolvers>
<modules>
  <module organisation="com.sun" name="tools" resolver="JDK"/>
</modules>

ivy.xml

<dependency org="com.sun" name="tools"/>

Works for me...