0

How can I get the CLASSPATH from the environment in a build.xml?

I've tried

<property environment="env"/>

<path id="classpath">
  <pathelement location="${env.CLASSPATH}"/>
</path>

<target name="compile">
  <javac includeantruntime="false">
    <src path="${src}"/>
    <classpath refid="classpath"/>
  </javac>
</target>

I have a feeling this is failing because ${env.CLASSPATH} is a colon-separated list. How then, can I get my classpath? I was surprised when ant didn't use my environment's CLASSPATH.

EDIT:

I've found a quick solution, but the preferred method is to use a separate properties file like the example here http://www.java2s.com/Code/Java/Ant/Useseparatepropertyfile.htm

Solution is, add

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

to the top of the build.xml

OregonTrail
  • 8,594
  • 7
  • 43
  • 58
  • Why would you want it to? One of the points of an ant file is to have a portable build environment that explicitly *doesn't* rely on environment settings. – Dave Newton Nov 22 '11 at 05:40
  • I want to do this because I'm using a version of junit which is stored in different locations on different machines on our network. I've relied on the environment CLASSPATH when using make. – OregonTrail Nov 22 '11 at 05:46
  • 1
    That kind of information belongs in a user- or machine-specific properties file. – Dave Newton Nov 22 '11 at 05:47

1 Answers1

0

Yes, it's failing because it's a colon-separated list. In general, it's considered a bad idea to specify the class-path externally and use it within Ant. This is because running the same Ant script on different machines may yield different results. Instead, you're better of specifying the class-path from within Ant.

Muel
  • 4,309
  • 1
  • 23
  • 32