Ant build.xml cannot find symbol in included .jar

Kevin Tanzer picture Kevin Tanzer · Oct 23, 2014 · Viewed 10.5k times · Source

I am migrating multiple projects from a purely desktop Eclipse dev & build to a buildserver (Jenkins-CI) environment. For this project, I can run the build.xml -> Run As -> Ant build successfully under Eclipse, but it fails when running on the buildserver. I feel I'm missing something elementary, but I've spent far to many hours looking at this. Any ideas what is missing?

<path id="lib-classpath">
    <!-- create a path to the lib files used in the javac compilation -->
    <fileset dir="${lib.dir}">
        <include name="*.jar"/>
    </fileset>
</path>

<target name="init">
    <mkdir dir="${bin.dir}"/>
    <mkdir dir="${lib.dir}"/>
</target>

<target name="check-DatabaseUtil">
    <property name="DatabaseUtil.dir" value="../../DatabaseUtil/workspace" />
    <property name="DatabaseUtil.jar" value="DatabaseUtil.jar" />
    <echo message="checking for ${DatabaseUtil.dir}/${DatabaseUtil.jar}..."/>
    <available file="${DatabaseUtil.dir}/${DatabaseUtil.jar}" property="DatabaseUtil.present"/>
</target>

<target name="do-if-DatabaseUtil" depends="check-DatabaseUtil" if="DatabaseUtil.present">
    <echo message="copy ${DatabaseUtil.dir}/${DatabaseUtil.jar} into directory ${lib.dir} ..."/>
    <copy file="${DatabaseUtil.dir}/${DatabaseUtil.jar}" todir="${lib.dir}" />
</target>

<target name="compile" depends="init, do-if-DatabaseUtil">
    <echo message="compile from directory ${source.dir} into directory ${bin.dir} ..." />
    <javac srcdir="${source.dir}" destdir="${bin.dir}">
        <classpath refid="lib-classpath"/>
    </javac>
</target>

<target name="jar" depends="compile">
    <property name="jar.name" value="${ant.project.name}.jar"/>
    <echo message="create file ${jar.name} ..." />
    <jar basedir="${bin.dir}" jarfile="${jar.name}">
        <fileset dir="${lib.dir}">
            <!-- include the library .jars into the file project .jar file -->
            <include name="*.jar"/>
        </fileset>
    </jar>
    <echo message="Done" />
</target>

when I run the build on the buildserver using Jenkins, it apparently fails to find the DatabaseUtil.jar that is present in the lib dir. Here's the recorded console output:

Ant compile failure:

Started by user anonymous
Building in workspace /var/lib/jenkins/workspace/ClassifyProcessor
Updating svn://10.10.10.194/proficient/ClassifyProcessor/trunk at revision '2014-10-23T11:41:59.153 -0400'
U         build.xml
U         .classpath
At revision 5181
[ClassifyProcessor] $ ant
Buildfile: /var/lib/jenkins/workspace/ClassifyProcessor/build.xml
     [echo] Starting project ClassifyProcessor using Java 1.7 and Apache Ant(TM) version 1.8.2 compiled on September 22 2011
Trying to override old definition of task javac
     [echo] Staring project ClassifyProcessor in /var/lib/jenkins/workspace/ClassifyProcessor ...

init:

check-DatabaseUtil:
     [echo] checking for ../../DatabaseUtil/workspace/DatabaseUtil.jar...

do-if-DatabaseUtil:

compile:
     [echo] compile from directory /var/lib/jenkins/workspace/ClassifyProcessor/src into directory /var/lib/jenkins/workspace/ClassifyProcessor/bin ...
    [javac] Compiling 32 source files to /var/lib/jenkins/workspace/ClassifyProcessor/bin
    [javac] /var/lib/jenkins/workspace/ClassifyProcessor/src/com/hco/processor/Main.java:81: error: cannot find symbol
    [javac]             fmsList = DatabaseService.getFaxMessageStatusRecordsByStatus("Converted", "Inbound", props.getFaxSourceList(), db_connection);
    [javac]                                      ^
    [javac]   symbol:   method getFaxMessageStatusRecordsByStatus(String,String,String[],Connection)
    [javac]   location: class DatabaseService
    [javac] /var/lib/jenkins/workspace/ClassifyProcessor/src/com/hco/processor/Main.java:107: error: cannot find symbol
    [javac]                     FaxMessageStatus fms = DatabaseService.getFaxMessageStatusRecordByIdAndStatus(fmsId, "Converted",  db_connection);
    [javac]                                                           ^
    [javac]   symbol:   method getFaxMessageStatusRecordByIdAndStatus(int,String,Connection)
    [javac]   location: class DatabaseService
    [javac] /var/lib/jenkins/workspace/ClassifyProcessor/src/com/hco/processor/Main.java:346: error: method insertInErrorLog in class DatabaseService cannot be applied to given types;
    [javac]                         DatabaseService.insertInErrorLog(faxMessageStatus.getHost(), "Classify", "Classify", cte.getMessage(), "WARNING", "", faxJobId, fmsId, db_connection);
    [javac]                                        ^
    [javac]   required: String,String,String,String,String,String,Connection
    [javac]   found: String,String,String,String,String,String,int,int,Connection
    [javac]   reason: actual and formal argument lists differ in length
    [javac] /var/lib/jenkins/workspace/ClassifyProcessor/src/com/hco/processor/Main.java:359: error: method insertInErrorLog in class DatabaseService cannot be applied to given types;
    [javac]                         DatabaseService.insertInErrorLog(faxMessageStatus.getHost(), "Classify", "Classify", e.getMessage(), "FATAL", "", faxJobId, fmsId, db_connection);
    [javac]                                        ^
    [javac]   required: String,String,String,String,String,String,Connection
    [javac]   found: String,String,String,String,String,String,int,int,Connection
    [javac]   reason: actual and formal argument lists differ in length
    [javac] 4 errors

BUILD FAILED
/var/lib/jenkins/workspace/ClassifyProcessor/build.xml:46: Compile failed; see the compiler error output for details.

Total time: 2 seconds
Build step 'Invoke Ant' marked build as failure
Sending e-mails to: ktanzer@<mycompany>.com
Finished: FAILURE

Answer

Siva Mandadi picture Siva Mandadi · Oct 23, 2014

Try <fileset dir="${lib.dir}"> <include name="**/*.jar"/> </fileset>