简体   繁体   中英

Ant javac build not correctly taking classpath elements and compilation failure

I have inherited a legacy project that used to build on Java 6 and now must be built on Java 8 in a DevOps scenario based on IBM Jazz RTC.

Formerly, the javac compiler was invoked with following classpath

    <path id="build.classpath">
        <fileset dir="${lib.artifactory}" includes="*.jar"/>
        <fileset dir="${common.lib.dir}" includes="*.jar"/>
        <fileset dir="${wls.lib.dir}" includes="*.jar"/>
        <fileset dir="${app.inf.lib.dir}" includes="*.jar"/> 
    <fileset dir="${web.inf.lib.dir}" includes="*.jar"/>
    <fileset dir="${myEar.dir}" includes="*.jar"/>
        <fileset dir="${weblogic.modules}" includes="*.jar"/>
        <pathelement location="${weblogic.jar}"/>
    </path>

After upgrade of the build machines to Java 8, Ant complained that the command line was too long.

So, we were instructed to change the build file in order not not use fileset element, but pathelement . build.xml is as follows:

    <path id="build.classpath">
        <pathelement location="${common.lib.dir}/*"/>
        <pathelement location="${wls.lib.dir}/*"/>
        <pathelement location="${app.inf.lib.dir}/*"/>
        <pathelement location="${web.inf.lib.dir}/*"/> 
        <pathelement location="${myEar.dir}/*"/>
        <pathelement location="${lib.artifactory}/*"/>
        <pathelement location="${weblogic.modules}/*"/>
        <pathelement location="${weblogic.jar}"/>
        <pathelement location="${wfm.jar}"/>
    </path>

  <target name="compile" depends="init">
    <javac target="${javacSourceTarget}" source="${javacSourceTarget}" debug="true" executable="${param.compilatore.executable}" fork="true" memoryMaximumSize="256m" srcdir="${srcWAR.dir}" destdir="${build.dir}" classpathref="build.classpath">
      <include name="${maijava}" />
      <include name="${package}/**/*" />
      <include name="${package2}/**/*" />
      <include name="${package3}/**/*" />
      <include name="${package4}/**/*" />
      <include name="${package5}/**/*" />
      <exclude name="${packagejdo}" />
    </javac>
  </target>

(The javac task was not changed)

So, now the build fails because it can't find some JARs located under ${app.inf.lib.dir} . For example, the following (redacted) occurs:

2022-09-05 13:11:29 [ExecTask         ]     [javac] Compiling 15 source files to /build/myEar_SRC/WORKAREA/elfi/classes  
2022-09-05 13:11:29 [ExecTask         ]     [javac] Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=ISO-8859-1  
2022-09-05 13:11:38 [ExecTask         ]     [javac] /build/myEar_SRC/SRC/elfi/war/src/com/acme/frontend/profilo/BeanProfilo.java:7: package com.acme.client does not exist  
2022-09-05 13:11:38 [ExecTask         ]     [javac] import com.acme.client.Response;  
2022-09-05 13:11:38 [ExecTask         ]     [javac]                                                ^  
2022-09-05 13:11:38 [ExecTask         ]     [javac] /build/myEar_SRC/SRC/elfi/war/src/com/acme/frontend/profilo/BeanProfilo.java:8: package com.acme.utils does not exist  
2022-09-05 13:11:38 [ExecTask         ]     [javac] import com.acme.utils.LogManager;  

We have triple checked the SFTP directory pointed by ${app.inf.lib.dir} and the jar is present.

I would like to understand why Ant is failing here and how can we import dozens of jars into the classpath without breaking the compilation process. I also can't display what jars are effectively included into the classpath.

You can use pathconvert to log (echo) the path, see Ant pathconvert is not accepting newlines

If the path is too long for the command line you could try to create a file from the pathconvert result (prefixed with "-cp ") and use it as "@argfile" for javac, see https://docs.oracle.com/javase/8/docs/technotes/tools/windows/javac.html#BHCCFGCD

In Ant it should be possible to pass that "@argfile" using the compilerarg element of the javac task.

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