tags:

views:

49

answers:

1

My ant build script starts with a java task that uses fork=true

<java fork="true"
  classname="org.apache.tools.ant.launch.Launcher"
  jvm="${java.home}/bin/java"
  classpathref="class.path">
  <arg value="-f" />
  <arg value="${ant.file}" />
  <arg value="generate" />
</java>

The <arg value="generate" /> points to another task in the same ant build file. This task starts another target with a subant task that points to another file.

<subant verbose="true" target="replace">
  <fileset dir="${basedir}" includes="refactor.xml" />
</subant>

This file refactor.xml starts a java task again with fork=true.

<java classpathref="class.path"
  classname="namespace.Tool"
  fork="true"/>

The strange behaviour is: everything works fine, except once in a while I get the NoClassDefFoundError error for the namespace.Tool java source file. After e.g. closing, reopening the file the error may disappear, however there is no reproducible behaviour.

I tried avoiding the subant construction (used to unclutter) but this doesn't help.

Finally the class.path that is referenced is like this:

<path id="class.path">
  <pathelement location="../common/bin" />
  <pathelement location="./bin" />
  <fileset dir="${build.dir}">
    <include name="...jar" />
  </fileset>
</path>

Any ideas?

A: 

Cause was <pathelement location="./bin" />.

This bin folder was recompiled by Eclipse as soon as in other steps in the sequence of Ant tasks e.g. a folder was deleted. The default setting in Eclipse is to recompile all code at such a moment.

As a result the Ant process may or may not find a specific class in this bin folder resulting in the inconsistent NoClassDefFoundError.

Gerard