views:

624

answers:

2

I put "stax-utils.jar" in the extensions directory ([JAVA_HOME]/jre/lib/ext), but ant's java task can't find it, giving:

java.lang.NoClassDefFoundError: javanet/staxutils/IndentingXMLStreamWriter

Strangely, it works for compilation: ant's javac task can find it. The problem is only with running code, with ant's java task...

  • If I use java from the command line, the jar is found and I can use classes from it.

  • If I explicitly give ant the classpath to that specific jar in the extension directory, it also works.

(I've seen this problem before, with one of the XML libraries.)

A: 

try adding it to ANT_HOME/lib

objects
No, that didn't work.
13ren
A: 

Are you certain that you use the JVM corresponding to your JAVA_HOME?

Thorbjørn Ravn Andersen
yes. <echo>${java.home}</echo> gives the jre that contains the lib/ext/staxutils.jar file
13ren
actually... you seem to be right... I did a little more hunting, and <echo>${java.vm.version}</echo> gives 10.0-b19... but the commandline java -version gives 1.6.0_04-b12 The weird thing is that I don't have build 10 installed (unless eclipse or netbeans installed it somewhere when I tried them out).
13ren
correction: 10.0-b19 is from "Java HotSpot(TM) Client VM (build 10.0-b19, mixed mode, sharing)", and I've confirmed that that is the one in JAVA_HOME (by going to the dir, and typing "./java -version"
13ren
It should be in JAVA_HOME/lib/ext, not jre/lib/ext. I think you are putting it in the wrong location.What is the reason that you want to have it in lib/ext? It will give you this problem MANY times over...
Thorbjørn Ravn Andersen
@Thorbjørn I have no preference: but JAVA_HOME/lib/ext does not exist in my Java 1.6 installation. The only ext I could find was in JAVA_HOME/jre/lib/ext. I'll try creating the directory you suggest (but I think if it was meant to me there, the installation would have created it).
13ren
@Thorbjørn No, that didn't help. Consider also that placing it where I did works for java (so it must be correct). The only problem is with ant.
13ren
So the JVM invoked by the javac task is right, but the JVM which ant is started in is not.I would investigate how your "ant" is invoked and which JVM the ant invoker script use.
Thorbjørn Ravn Andersen