views:

488

answers:

1

I am new to using ANT and am trying to include third party jars in the build using Eclipse 3.5. I keep getting "cannot find symbol" errors in the compilation, so obviously it is not taking these two jars into consideration. If anyone can show me where I am going wrong, or suggest another route, I would appreciate it. Thanks.

JarPath below is the path to my project in the Eclipse workspace. It tried '/' and '\' in the path and neither mattered.

<?xml version="1.0" ?>
<project default="main">
    <property name="env.JAVA_HOME" location="C:\Program Files\Java\jdk\bin\javac.exe"/>
    <property name="jars.dir" location="JarPath"/>

    <target name="main" depends="compile, compress" description="Main target">
        <echo>
            Building the .jar file.
        </echo>
    </target>

    <target name="compile" description="Compilation target">
        <javac srcdir="." fork="yes" executable="${env.JAVA_HOME}"/>
        <classpath>        
         <pathelement location="${jars.dir}/A.jar"/>        
         <pathelement location="${jars.dir}/B.jar"/>    
        </classpath>
    </target>

  <target name="compress" description="Compression target">
        <jar jarfile="MyJar.jar" basedir="." includes="*.class" />
  </target>
</project>
+1  A: 

I always use a nested fileset element inside the classpath element. You can specify specific files or use globbing. It should look something likethis:

<classpath id="classpath" description="The default classpath.">
  <pathelement path="${classpath}"/>
  <fileset dir="lib">
    <include name="jaxp.jar"/>
    <include name="crimson.jar"/>
    <include name="ojdbc14.jar"/>
  </fileset>
</classpath>

You can also use the include element to glob, ie

<include name="*.jar/>

So you can include any jar.

Julian Simpson
Thanks a lot. One problem was if you notice above my classpath tag is not within the javac tag. once i move it within there it did compile. It compiles using your method too.
Ken