简体   繁体   中英

Ant build.xml cannot find symbol in included .jar

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

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

Make it point to your exact jar files directory where jars are present

<path id="classpath">
            <fileset dir="${main.jar}" includes="**/*.jar"/>
        <!-- <pathelement location="${src.dir}" />-->
    </path>

----in my case jar files present in ----
<property name="main.jar"     value="jar"/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM