tsm
tsm

Reputation: 3658

Adding to Java classpath breaks ant

I wanted to have a certain JAR in my classpath for easy access with a Jython REPL. So in my .bashrc I put:

export CLASSPATH=:/home/tmacdonald/path/to/jar/thing.jar

However, this breaks ant both for compiling that JAR can compiling a JAR from a different subpackage:

$ ant jar
Invalid implementation version between Ant core and Ant optional tasks.
 core    : 1.8.0 in file:/usr/share/ant/lib/ant.jar
 optional: 1.5.1 in file:/home/tmacdonald/path/to/jar/lib/gt2-2.3.3/ant-optional-1.5.1.jar
$ echo $CLASSPATH
:/home/tmacdonald/path/to/jar/thing.jar

Changing the classpath fixes it:

$ export CLASSPATH=
$ !ec
echo $CLASSPATH

$ ant jar
[Compiles successfully.]

But it seems awkward and not The Right Thing to have to keep changing my classpath, depending on whether I wanted to run ant or a Jython REPL. I'll admit that my knowledge of both ant and the classpath is pretty weak. I just think of the classpath as being, "PATH for Java libraries; or PYTHONPATH for Java", and I only ever add small changes to existing ant config files I inherited--I've never had to set one up.

So I'd be interested to hear what's really happening (and incidentally how that causes my problem) so I can be a little bit more educated, and of course I'd also like a fix. Thanks!

Upvotes: 1

Views: 1964

Answers (1)

duffymo
duffymo

Reputation: 308743

I don't think Ant should know or care about environment variables. The right way to do it is to set CLASSPATH inside the Ant build.xml itself.

Here are production and test classpaths that I use in my Ant build.xml files:

<path id="production.class.path">
    <pathelement location="${production.classes}"/>
    <pathelement location="${production.resources}"/>
    <fileset dir="${production.lib}">
        <include name="**/*.jar"/>
    </fileset>
</path>

<path id="test.class.path">                            
    <path refid="production.class.path"/>
    <pathelement location="${test.classes}"/>
    <pathelement location="${test.resources}"/>
    <fileset dir="${test.lib}">
        <include name="**/*.jar"/>
    </fileset>
</path>

As you can see, there are no references to ${classpath}, nor should there be.

Upvotes: 2

Related Questions