title: Ant loadproperties failed (bcel error?)
body: <p>I'm working on a simple build script that should get some constants from a java class file and use them as the version numbers in my file names. I use Eclipse and its own Ant, but put <em>bcel-5.2.jar</em> in my libs folder and into the classpath for the Ant call.</p>
  
  <pre><code>&lt;target name="generate_version" depends="compile"&gt;
      &lt;loadproperties srcfile="${dir.dest}/MyVersion.class"&gt;
          &lt;classpath&gt;
              &lt;fileset dir="${dir.libs}"&gt;
                  &lt;include name="**/bcel*.jar"/&gt;
              &lt;/fileset&gt;
          &lt;/classpath&gt;
  
          &lt;filterchain&gt;
              &lt;classconstants/&gt;
          &lt;/filterchain&gt;
      &lt;/loadproperties&gt;
  &lt;/target&gt;
  </code></pre>
  
  <p>But unfortunatly the ant task <em>loadproperties</em> fails:</p>
  
  <pre><code>build.xml:46: expected a java resource as source
  </code></pre>
  
  <p>After that I tried to run Ant from outside Eclipse, using this command line:</p>
  
  <pre><code>set ANT_HOME=C:\Program Files\Java\ant\apache-ant-1.7.1
  "%ANT_HOME%\bin\ant.bat"
  </code></pre>
  
  <p>The result is</p>
  
  <pre><code>Buildfile: build.xml
  
  init:
       [echo] Building project.
       [echo] ant.home:          C:\Program Files\Java\ant\apache-ant-1.7.1
       [echo] ant.java.version:  1.6
       [echo] ant.version:       Apache Ant version 1.7.1 compiled on June 27 2008
  
  compile:
      [javac] Compiling 262 source files to **********\build
      [javac] Note: Some input files use or override a deprecated API.
      [javac] Note: Recompile with -Xlint:deprecation for details.
      [javac] Note: Some input files use unchecked or unsafe operations.
      [javac] Note: Recompile with -Xlint:unchecked for details.
  
  generate_version:
  
  BUILD FAILED
  ********************\ant\build.xml:46: expected a java resource as source
  </code></pre>
  
  <p>I'm really lost now. Is it a bcel error? Is it an Ant incompatibility with my own bcel?</p>
  
  <p>One last hint: Removing the bcel classpath entry from the Ant target results in this:</p>
  
  <pre><code>Buildfile: build.xml
  
  init:
       [echo] Building project.
       [echo] ant.home:          C:\Program Files\Java\ant\apache-ant-1.7.1
       [echo] ant.java.version:  1.6
       [echo] ant.version:       Apache Ant version 1.7.1 compiled on June 27 2008
  
  compile:
      [javac] Compiling 262 source files to ********************\build
      [javac] Note: Some input files use or override a deprecated API.
      [javac] Note: Recompile with -Xlint:deprecation for details.
      [javac] Note: Some input files use unchecked or unsafe operations.
      [javac] Note: Recompile with -Xlint:unchecked for details.
  
  generate_version:
  
  BUILD FAILED
  java.lang.NoClassDefFoundError: org/apache/bcel/classfile/ClassParser
          at org.apache.tools.ant.filters.util.JavaClassHelper.getConstants(JavaClassHelper.java:47)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
  </code></pre>
  
  <p><strong>UPDATE</strong> After setting the Ant preferences in Eclipse, the error message changed:</p>
  
  <pre><code>BUILD FAILED
  *********************\build.xml:46: org.apache.bcel.classfile.ClassFormatException:  is not a Java .class file
      at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:115)
      at org.apache.tools.ant.Task.perform(Task.java:348)
      at org.apache.tools.ant.Target.execute(Target.java:357)
      at org.apache.tools.ant.Target.performTasks(Target.java:385)
      at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1329)
      at org.apache.tools.ant.Project.executeTarget(Project.java:1298)
      at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
      at org.eclipse.ant.internal.ui.antsupport.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
      at org.apache.tools.ant.Project.executeTargets(Project.java:1181)
      at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(InternalAntRunner.java:423)
      at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main(InternalAntRunner.java:137)
  </code></pre>
  
  <p>Now I think it's maybe a version conflict between Ant and BCEL. Or BCEL and JDK1.6. Or Eclipse and BCEL and Ant or JDK... I'm lost.</p>
  
  <hr>
  
  <p><strong>ANSWER:</strong></p>
  
  <p>This is the comment found below </p>
  
  <blockquote>
    <p>I should have mentioned this - you do not need to convert anything. Doc: "since Ant 
    1.7, the character encoding ISO-8859-1 is used to convert from characters back to 
    bytes, so ONE HAS TO USE THIS ENCODING for reading the java class file." This is just a 
    convention to get round the fact that a character filter is being used on raw bytes. 
    ant.apache.org/manual/CoreTypes/… Using UTF-8 would be bad! – McDowell </p>
  </blockquote>