我是Ant的新手,当前有一个新的Java Web应用程序构建,需要ant的支持,一个Web应用程序依赖于b Web应用程序,并将其作为JAR依赖项添加到lib文件夹中,因此如果有一些更新在b上,那么我需要重建b并生成一个新的JAR,然后替换a的依赖项。
就像我说的那样,我在b应用程序的一个Java文件中更改了一点代码,然后进行编译,然后解压缩b JAR依赖项以替换该类文件并将其重新压缩为JAR文件。当我构建它时,会发生错误并显示编译失败。
根据JDK1.6这两个Java应用程序,加上我也检查jar文件的源代码是JDK 1.6,所以我使用JDK 1.6编译javac updatedJava.java
,还有一件事是,如果我不取代这个类文件,它可以在Jenkins中成功构建,而一旦我更新了该类文件,它将失败。
我真的不熟悉Ant。这是我的应用程序详细信息和一些错误日志:
应用架构:
A
|-src
|-web
|- WEB-INFO
|- web.xml
|- lib
|- B.jar
|- webex-build.xml
B
|- src
|- updatedJar.java
|- build
|- classes
|- target
|- B.jar
A的蚂蚁生成文件:
<project name="A" default="war" basedir=".">
<property file="../build.properties"/>
<property name="version" value="1.0"/>
<property name="dir.root" value="."/>
<echo>#####################################################################</echo>
<echo># Building ${ant.project.name} Version is ${version}</echo>
<echo>#####################################################################</echo>
<!--property name="WL_HOME" value="D:/bea" /-->
<property name="app.lib" value="web/WEB-INF/lib" />
<property name="server.lib" value="${wl.home}/server/lib"/>
<property name="modules.lib" value="${bea.home}/modules" />
<property name="configfile_env" value="web_message_${env}.properties" />
<!-- set local properties for this build -->
<path id="lib.classpath">
<fileset dir="${app.lib}">
<include name="*.jar"/>
</fileset>
<pathelement location="${modules.lib}/javax.servlet_1.0.0.0_2-5.jar"/>
<pathelement location="${server.lib}/ojdbc6.jar"/>
</path>
<property name="build" value="build"/>
<property name="src" value="src/java"/>
<property name="config" value="src/configsrc/"/>
<property name="srcjaxws" value="src/jaxwssource"/>
<property name="adapter" value="src/adapter"/>
<property name="reports.junit.xml.dir" value="junit/reports"/>
<property name="project.test.java.dir" value="src/test"/>
<property name="project.target.dir" value="target"/>
<target name="init">
<tstamp/>
<delete dir="${build}"/>
<mkdir dir="${build}"/>
</target>
<target name="compile" depends="init">
<mkdir dir="${build}/classes"/>
<javac destdir="${build}/classes" debug="on" includeantruntime="false">
<src path="${srcjaxws}"/>
<src path="${src}"/>
<src path="${adapter}"/>
<classpath refid="lib.classpath"/>
<compilerarg value="-Xlint"/>
</javac>
<copy todir="${build}/classes/" overwrite="true" preservelastmodified="true" failonerror="true" verbose="true" flatten="false">
<fileset dir="${config}"/>
</copy>
<!--if>
<isset property="env" />
<then>
<echo>ENV is set as ${env}</echo>
<copy tofile="${build}/classes/config/system/web_message.properties" file="${build}/classes/config/config_env/web_message_${env}.properties" overwrite="true" />
</then>
<else>
<echo>There is no env set, if you want to set, please use -Denv=dev/qa/devint/pp/prod</echo>
</else>
</if-->
</target>
<target name="test" depends="compile">
<echo message="Testing..."/>
<delete dir="${project.target.dir}" />
<delete dir="${reports.junit.xml.dir}" />
<mkdir dir="${project.target.dir}" />
<mkdir dir="${reports.junit.xml.dir}" />
<javac destdir="${build}/classes" debug="true" includeantruntime="false">
<src path="${project.test.java.dir}"/>
<classpath>
<path refid="lib.classpath"/>
</classpath>
<classpath path="${build}/classes" />
</javac>
<taskdef name="junit" classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask">
<classpath>
<path refid="lib.classpath"/>
</classpath>
</taskdef>
<!-- Import the JaCoCo Ant Task -->
<taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml">
<!-- Update the following line, or put the "jacocoant.jar" file in your "$HOME/.ant/lib" folder -->
<classpath path="${app.lib}/jacocoant.jar" />
</taskdef>
<!-- Run your unit tests, adding the JaCoCo agent -->
<jacoco:coverage destfile="${project.target.dir}/jacoco-unit.exec" xmlns:jacoco="antlib:org.jacoco.ant">
<junit fork="yes" failureProperty="test.failed">
<classpath refid="lib.classpath" />
<classpath location="${build}/classes" />
<classpath location="${build}" />
<formatter type="xml" />
<batchtest todir="${reports.junit.xml.dir}">
<fileset dir="${build}/classes">
<include name="**/*Test.class" />
</fileset>
</batchtest>
</junit>
</jacoco:coverage>
<echo message="Test completed..."/>
</target>
<target name="war" depends="compile">
<mkdir dir="${build}/wls10"/>
<wars classes-dir="${build}/classes" build-dir="${build}"/>
</target>
<macrodef name="wars">
<attribute name="classes-dir"/>
<attribute name="build-dir"/>
<sequential>
<war-task classes-dir="@{classes-dir}" build-dir="@{build-dir}" generic="javaee5" appserver="wls10"/>
</sequential>
</macrodef>
<macrodef name="war-task">
<attribute name="classes-dir"/>
<attribute name="build-dir"/>
<attribute name="generic"/>
<attribute name="appserver"/>
<sequential>
<war destfile="@{build-dir}/@{appserver}/WebexPFProxyWS.war" webxml="web/WEB-INF/web.xml">
<classes dir="@{classes-dir}"></classes>
<webinf dir="web/WEB-INF" includes="web*.xm*"/>
<manifest></manifest>
<lib dir="${app.lib}">
<include name="*.jar"/>
</lib>
<webinf dir="web/WEB-INF" includes="wsdl/**"/>
<fileset dir="web">
<include name="**/*.jsp"/>
</fileset>
</war>
</sequential>
</macrodef>
</project>
错误日志中詹金斯当执行ant构建:
线41为<javac destdir="${build}/classes" debug="on" includeantruntime="false">
在上面的XML。
[exec] [javac] XMLSerializer serializer = getXMLSerializer(writer, null);
[exec] [javac] ^
[exec] [javac] Note: Some input files additionally use unchecked or unsafe operations.
[exec] [javac] 100 errors
[exec] [javac] 116 warnings
[exec]
[exec] BUILD FAILED
[exec] /apps/dftjenkins/jenkins_node/workspace/java/A/webex-build.xml:41: Compile failed; see the compiler error output for details.
[exec]
[exec] Total time: 3 seconds
BUILD FAILED
/apps/dftjenkins/JENKINS_HOME_NODES/selfservices-build-scripts-stash/Proxy/build_ht.xml:149: The following error occurred while executing this line:
/apps/dftjenkins/JENKINS_HOME_NODES/selfservices-build-scripts-stash/Common/build_process.xml:517: The following error occurred while executing this line:
/apps/dftjenkins/JENKINS_HOME_NODES/selfservices-build-scripts-stash/Common/build_common.xml:179: The following error occurred while executing this line:
/apps/dftjenkins/JENKINS_HOME_NODES/selfservices-build-scripts-stash/Common/build_common.xml:182: exec returned: 1
Total time: 7 seconds
Build step 'Invoke Ant' marked build as failure
Running post build processes
答案 0 :(得分:0)
当类路径上有一个无效的jar时,它将被静默忽略。鉴于您遇到了一堆构建错误,这听起来像是在发生:您的代码取决于该jar中的类,并且该jar由于无效而实际上消失了。
尤其是在早期的Java版本中,“一个jar只是一个zip文件”并不是真的:虽然解压缩可以成功解压缩一个jar,但是使用“ zip”工具生成的任何旧zip文件不一定是有效的jar。
我将从使用jar工具(而不是zip)开始添加/替换类文件。