4

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?

mikey
  • 169
  • 5

2 Answers2

4

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
Mark O'Connor
  • 76,015
  • 10
  • 139
  • 185
  • and if java.home points to a jdk the /../ part is wrong. lib/ is directly under java.home: file:///${java.home}/lib/tools.jar – oers Jan 13 '12 at 07:53
  • the problem is that the file is not being found, it's that the protocol is incorrect. i have everything set correctly and the file path that it prints out is correct. – mikey Jan 13 '12 at 20:13
  • on another note, in some systems, JAVA_HOME will point to the JRE and not the JDK installation. as long as you keep your systems consistent with how you are planning on using them. in our case, how i'm setting it is consistent with our systems. – mikey Jan 13 '12 at 20:14
  • The ANT installation doc recommends pointing JAVA_HOME at the JDK as some tasks require the tools jar. http://ant.apache.org/manual/install.html – Mark O'Connor Jan 13 '12 at 23:19
  • so it looks like even i was confused. i researched it a bit, and JAVA_HOME is an environment variable and java.home is a system property setup by java. JAVA_HOME should point to JDK, but java.home is a java property that points to the JRE install. my JAVA_HOME is pointing to my JDK and java.home points to my JRE folder under JAVA_HOME. if you do a search for "JAVA_HOME vs java.home" it should bring up some of the pages i looked at. – mikey Jan 14 '12 at 00:25
  • Yup, ANT uses JAVA_HOME (the environment variable). – Mark O'Connor Jan 14 '12 at 11:19
2

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

krico
  • 5,723
  • 2
  • 25
  • 28