1
votes

I set this property in my build.xml script of ant to ignore the system classpath during build, but ant still picks up the system classpath in my java call and merges it with my classpath specified in the build script.

<property name="build.sysclasspath" value="ignore" />

<path id="classpath">
    <pathelement path="${buildDir}/classes" />
    <fileset dir="${prjdir}">
        <include name="lib/*.jar"/>
    </fileset>
</path>

<java classname="com.ibm.biginsights.fs.gpfs.LoggingInjector" failonerror="true">
    <classpath refid="classpath" />
</java>

If I unset the $CLASSPATH environment variable before calling ant everything works fine. What's the problem?

2

2 Answers

2
votes

ANT is itself a java program so it's difficult to prevent tasks from using the same system classpath.

To properly isolate your java build, I'd recommend to setting the following attributes on the javac task:

<javac .... includeAntRuntime="false" includeAntRuntime="false" ...

Similarily, when running java programs, set the fork attribute so that it runs in another VM:

<java  ...fork="true" classpathref="class.path.that.i.control"...
1
votes

This property, AFAIK, is a system property that must be passed to ant (using ant -Dbuild.sysclasspath=ignore). But unsetting the CLASSPATH is probably as easy.

The main problam, IMO, is to use the CLASSPATH environment variable in the first place. I find it preferrable to always use the -cp or -jar option whan using Java, and not to rely on the system CLASSPATH. As soon as you have two Java programs that both rely on the system CLASSPATH, there is a risk of a clash between the dependencies of these two programs.