简体   繁体   English

Ant javac 构建未正确采用类路径元素和编译失败

[英]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.我继承了一个遗留项目,该项目过去在 Java 6 上构建,现在必须在基于 IBM Jazz RTC 的 DevOps 场景中构建在 Java 8 上。

Formerly, the javac compiler was invoked with following classpath以前,javac 编译器是使用以下类路径调用的

    <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.将构建机器升级到 Java 8 后,Ant 抱怨命令行太长。

So, we were instructed to change the build file in order not not use fileset element, but pathelement .因此,我们被指示更改构建文件,以便使用fileset元素,而是使用pathelement元素。 build.xml is as follows: build.xml如下:

    <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) javac任务没有改变)

So, now the build fails because it can't find some JARs located under ${app.inf.lib.dir} .所以,现在构建失败了,因为它找不到位于${app.inf.lib.dir}下的一些 JARs 。 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.我们对${app.inf.lib.dir}指向的 SFTP 目录进行了三次检查,并且 jar 存在。

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.我想了解为什么 Ant 在这里失败,我们如何在不破坏编译过程的情况下将数十个 jars 导入类路径。 I also can't display what jars are effectively included into the classpath.我也无法显示哪些 jars 有效地包含在类路径中。

You can use pathconvert to log (echo) the path, see Ant pathconvert is not accepting newlines您可以使用 pathconvert 记录(回显)路径,请参阅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如果命令行的路径太长,您可以尝试从 pathconvert 结果创建一个文件(以“-cp”为前缀)并将其用作 javac 的“@argfile”,请参阅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.在 Ant 中,应该可以使用 javac 任务的 compilerarg 元素传递该“@argfile”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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