当前位置: 首页 > 知识库问答 >
问题:

调用ant目标时发生java.uti.zip.ZipException错误

姬高澹
2023-03-14

在调用ANT目标时,我得到以下错误。我尽了最大的努力来解决这个问题,但没有。

Unable to obtain resource from C:\uiunit\log4j.properties: java.util.zip.ZipException: error in opening zip file
[junit] Unable to obtain resource from C:\uiunit\log4j.properties:
[junit] java.util.zip.ZipException: error in opening zip file
[junit]     at java.util.zip.ZipFile.open(Native Method)
[junit]     at java.util.zip.ZipFile.<init>(ZipFile.java:214)
[junit]     at java.util.zip.ZipFile.<init>(ZipFile.java:144)
[junit]     at java.util.jar.JarFile.<init>(JarFile.java:152)
[junit]     at java.util.jar.JarFile.<init>(JarFile.java:116)
[junit]     at org.apache.tools.ant.AntClassLoader.getResourceURL(AntClassLoader.java:1006)
[junit]     at org.apache.tools.ant.AntClassLoader$ResourceEnumeration.findNextResource(AntClassLoader.java:149)
[junit]     at org.apache.tools.ant.AntClassLoader$ResourceEnumeration.<init>(AntClassLoader.java:110)
[junit]     at org.apache.tools.ant.AntClassLoader.findResources(AntClassLoader.java:953)
[junit]     at org.apache.tools.ant.AntClassLoader.getNamedResources(AntClassLoader.java:922)
[junit]     at org.apache.tools.ant.loader.AntClassLoader5.getResources(AntClassLoader5.java:58)
[junit]     at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.checkForkedPath(JUnitTask.java:1181)
[junit]     at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.executeAsForked(JUnitTask.java:1061)
[junit]     at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:855)
[junit]     at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.executeOrQueue(JUnitTask.java:1903)
[junit]     at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:804)
[junit]     at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
[junit]     at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
[junit]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[junit]     at java.lang.reflect.Method.invoke(Method.java:601)
[junit]     at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
[junit]     at org.apache.tools.ant.Task.perform(Task.java:348)
[junit]     at org.apache.tools.ant.Target.execute(Target.java:435)
[junit]     at org.apache.tools.ant.Target.performTasks(Target.java:456)
[junit]     at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1393)
[junit]     at org.apache.tools.ant.Project.executeTarget(Project.java:1364)
[junit]     at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
[junit]     at org.apache.tools.ant.Project.executeTargets(Project.java:1248)
[junit]     at org.apache.tools.ant.Main.runBuild(Main.java:851)
[junit]     at org.apache.tools.ant.Main.startAnt(Main.java:235)
[junit]     at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
[junit]     at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
[junit] DEBUG com.cordys.cm.uiunit.config.IConfiguration - Using config file: "/C:/uiunit/UIUnit.properties" (-2009166949)
[junit] null
[junit] Running test.CapsInstallerTest
[junit] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.184 sec
[junit] Test test.CordysCapsInstallerTest FAILED

[junitreport]正在处理D:\checkouts\guiinstaller\tests-capsinstallertest-suites.xml到D:\checkouts\guiunit.build.junit.report\junit-nof[junitreport]加载样式表jar:file:/d:/checkouts/ant/lib/ant-junit.jar!/org/apache/tools/ant/taskdefs/optional/junit/xsl/junit-noframes.xsl[junitreport]转换时间:499ms

观察:-如果我通过eclipse执行编译操作,那么ANT目标调用工作正常。如果我通过ANT执行编译操作,则ANT目标调用失败,出现上述错误。

<project name="GUITest" basedir="." default="installBOP">
<property environment="env" />
<property file="installer.properties"/>
<property file="uninstaller.properties"/>
<property file="c:/uiunit/uiunit.properties" />
<property name="src" location="src" />
<property name="src.test" location="src/test" />
<property name="fit" location="fit" />
<property name="bin" location="bin" />
<property name="lib" location="lib" />
<property name="guiunit.build.junit.report" location="guiunit.build.junit.report" />
<property name="report" location="report" />
<property name="report.run" location="report/run" />
<property name="REPORTNAME" location="CordysCapsInstallerTest" />

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

    <path id="test.classpath">
    <path refid="lib.classpath" />
    <pathelement location="${bin}" />
    <pathelement location="C:/uiunit" />
    </path>

<condition property="OsName" value="Windows">
    <os family="windows"/>
</condition>
<condithtml" target="_blank">ion property="OsName" value="Linux">
    <os name="Linux"/>
</condition>
<condition property="OsName" value="aix">
    <os name="AIX"/>
</condition>
<condition property="OsName" value="SunOS">
    <os name="SunOS"/>
</condition>
<condition property="isUnix">
    <os family="unix"/>
</condition>
<condition property="onOracle">
    <equals arg1="${env.DB_VENDOR_NAME}" arg2="Oracle 9i / 10g / 11g"/>
</condition>
<condition property="onWindows">
    <os family="Windows"/>
</condition>
<condition property="onLinux">
    <os name="Linux"/>
</condition>
<condition property="onAix">
    <os name="AIX"/>
</condition>

<condition property="is64bit" value="-64bit" else="">
    <and>
        <os arch="amd64"/>
        <not>
            <equals arg1="${branch.name}" arg2="BOP4-CU"/>
        </not>
        <not>
            <equals arg1="${branch.name}" arg2="BOP4-CU-Release"/>
        </not>
    </and>
</condition>

<target name="help">
    <echo>ant upgrade: Upgrade the cordys</echo>
    <echo>ant install: Install the cordys</echo>
    <echo>ant uninstall: Uninstall the cordys</echo>
</target>

<target name="clean">
    <delete dir="${bin}" />
    <delete dir="${report}" />
</target>

<target name="compile" depends="clean">
    <mkdir dir="${bin}" />
    <!--<javac includeantruntime="false" srcdir="${src}" destdir="${bin}">
        <classpath refid="test.classpath" />            
    </javac>-->
    <javac destdir="${bin}" debug="${debug}" nowarn="${debug}" deprecation="${deprecation}" optimize="${optimize}">
        <classpath refid="test.classpath" />
        <src path="${src}" />
    </javac>
</target>

<target name="copy-installer" unless="dont.download">
    <echo message="Fetching build number...." />
    <taskdef resource="net/sf/antcontrib/antcontrib.properties" classpath="${lib}/commons-net-2.2.jar" />
    <ftp
        action="get"
        server="${ftp.server.name}"
        userid="${ftp.user.name}"
        remotedir="${ftp.remote.dir}/${branch.name}"
        password="${ftp.user.password}"
        passive="true">
        <fileset  dir="${basedir}">
            <include name="build.number" />
            <include name="build.properties"/>
        </fileset>
    </ftp>
    <move file="build.number" tofile="buildnumber.properties"/>
    <property file="${basedir}/build.properties"/>
    <property file="${basedir}/buildnumber.properties"/>
    <delete dir="${basedir}/installers" failonerror="false"/>
    <condition property="buildfolder" value="" else="/build.${build.number}">
        <or>
            <equals arg1="${branch.name}" arg2="BOP4-CU"/>
            <equals arg1="${branch.name}" arg2="BOP4-CU-Release"/>
        </or>
    </condition>
    <echo message="Fetching installer.... from ${ftp.remote.dir}/${branch.name}${buildfolder}/external/${OsName}${is64bit}" />
    <ftp
        action="get"
        server="${ftp.server.name}"
        userid="${ftp.user.name}"
        remotedir="${ftp.remote.dir}/${branch.name}${buildfolder}/external/${OsName}${is64bit}"
        password="${ftp.user.password}" 
        passive="true">
        <fileset  dir="${basedir}/installers">
            <include name="${name.dist.zip.file}"/>
        </fileset>
     </ftp>
    <unzip src="${basedir}/installers/${name.dist.zip.file}" dest="${basedir}/installers"/>
    <chmod dir="${basedir}/installers" perm="ugo+rx" includes="*.bin" osfamily="unix"/>
    <delete file="${basedir}/installers/${name.dist.zip.file}"/>
</target>

 <target name="installTilBaseline" depends="compile,copy-installer">
    <echo message="${log4j.rootCategory}"/>
    <mkdir dir="${report.run}" />        
    <java fork="true" classname="test.GUITest" failonerror="true">
        <arg line="install"/>
        <!--jvmarg line="-Dlog4j.configuration=${basedir}/lib/log4j.properties"/-->
        <classpath>
            <path refid="test.classpath"/>
            <path location = "$(bin)" />
            <pathelement location="${env.JAVA_HOME}/lib/tools.jar"/>
            <pathelement location="${env.Path}"/>
        </classpath>            
    </java>
    <echo message="${env.classpath}"/>      
</target>

<target name="uninstallBOP" depends="compile">
    <mkdir dir="${report.run}" />        
        <java fork="true" classname="test.GUITest" failonerror="true">
            <arg line="uninstall"/>
            <classpath>
                <path refid="test.classpath"/>
                <path location = "$(bin)" />
                <pathelement location="${env.JAVA_HOME}/lib/tools.jar"/>
                <pathelement location="${env.Path}"/>
            </classpath>
        </java>
    <echo>Please see the run report page for more details</echo>        
</target>

<target name="upgradeTilBaseline" depends="compile,copy-installer">
    <mkdir dir="${report.run}" />        
        <java fork="true" classname="test.GUITest" failonerror="true">
            <arg line="upgrade"/>
            <classpath>
                <path refid="test.classpath"/>
                <path location = "$(bin)" />
                <pathelement location="${env.JAVA_HOME}/lib/tools.jar"/>
                <pathelement location="${env.Path}"/>
            </classpath>
        </java>
    <echo>Please see the run report page for more details</echo>
</target>

<target name="launch-rc-server" if="${selenium.server.ant}" >
    <mkdir dir="${report.run}"/>
    <taskdef resource="net/sf/antcontrib/antcontrib.properties" classpath="${lib}/ant-contrib-1.0b1.jar" />
    <taskdef name="stringutil" classname="ise.antelope.tasks.StringUtilTask" classpath="${lib}/antelopetasks-3.2.10.jar" />
    <stringutil string="${seleniumserver}" property="indexofcom">
        <indexof string=":" />
    </stringutil>
    <stringutil string="${seleniumserver}" property="temp">
        <substring beginindex="${indexofcom}" />
    </stringutil>
    <stringutil string="${temp}" property="hub.port">
        <replace regex=":" replacement="" />
    </stringutil>
    <if>
    <equals arg1="${browsertype}" arg2="safariproxy" />
    <then>
        <property name="selenium.server" value="selenium-server-standalone-2.0b3.jar"/>
    </then>
    <else>
        <property name="selenium.server" value="selenium-server-standalone-2.32.0.jar"/>
    </else>
    </if>
    <if>
        <istrue value="${browser.session.reuse}"/>
        <then>
            <property name="temp.selenium.args" value="-port ${hub.port} -browserSessionReuse" />
        </then>
        <else>
            <property name="temp.selenium.args" value="-port ${hub.port}" />
        </else>
    </if>
    <if>
        <isset  property="selenium.args.custom"/>
        <then>
            <property name="selenium.args" value="${temp.selenium.args} ${selenium.args.custom}" />
        </then>
        <else>
            <property name="selenium.args" value="${temp.selenium.args}" />
        </else>
    </if>
    <echo>/K start java -jar lib/${selenium.server} ${selenium.args}</echo>
    <exec dir="." executable="cmd" spawn="false" output="${report.run}/startsel-output.txt" logerror="true">
        <arg line="/K start java -jar lib/${selenium.server} ${selenium.args}"/>
    </exec>
    <sleep seconds="10"/>
    <antcall target="waitForSeleniumServer" />
</target>

<target name="waitForSeleniumServer" description="wait till selenium server starts"  if="${selenium.server.ant}">
    <echo taskname="waitfor" message="Wait for proxy server launch" />
    <waitfor maxwait="2" maxwaitunit="minute" checkevery="100">
        <http url="http://${seleniumserver}/selenium-server/driver/?cmd=testComplete"/>
    </waitfor>
</target>

<target name="shutdown-rc-server" description="this will shutdown RC" if="${selenium.server.ant}">
    <echo>seleniumserver is ${seleniumserver}</echo>
    <java classname="com.selenium.remotecontrol.ShutDownRC" fork="true" failonerror="true">
        <jvmarg value="-Durl=http://${seleniumserver}" />
        <classpath>
            <fileset dir="${basedir}/lib">
                <include name="commons-httpclient-3.0.1.jar" />
                <include name="commons-logging-*.jar" />
                <include name="commons-codec-1.5.jar" />
                <include name="shutdownrc.jar" />
            </fileset>
        </classpath>
    </java>
    <sleep seconds="3"/>
</target>

<target name="installcaps" depends="launch-rc-server">
<echo>${test.classpath}</echo>
<mkdir dir="${guiunit.build.junit.report}" />
<!-- do necessary setup-->
<junit fork="yes" failureproperty="junit.failed" dir="${basedir}"
    filtertrace="on" 
    haltonfailure="no" printsummary="on"
    showoutput="yes">
    <classpath>
        <path refid="test.classpath"/>
        <pathelement location="${env.JAVA_HOME}/lib/tools.jar"/>
        <pathelement location="${env.Path}"/>
        <pathelement location="${bin}"/>
    </classpath>        
    <formatter type="xml"/>
    <test name="test.CordysCapsInstallerTest" todir="${guiunit.build.junit.report}"/>
</junit>
<junitreport tofile="TESTS-CordysCapsInstallerTest-Suites.xml">
    <fileset dir="${guiunit.build.junit.report}">
        <include name="**/TEST-*.xml"/>
    </fileset>
    <report format="noframes" todir="${guiunit.build.junit.report}"/>
</junitreport>
<antcall target="shutdown-rc-server" />
</target>

<target name="installBOP" depends="installTilBaseline,installcaps">
    <echo>Installation of BOP is completed</echo>
</target>

<target name="upgradeBOP" depends="upgradeTilBaseline,installcaps">
    <echo>Upgrade of BOP is completed</echo>
</target>

<target name="buildjar">

</target>

当我调用$>ant installcaps目标时,我以前经常会得到上面的错误,之后,通过遵循Guillaume Darmont的注释,我从类路径中删除了C:\UIUnit\log4j.properties值,然后出现了下面的错误

D:\checkouts\GUIInstaller>ant installcaps

BuildFile:d:\checkouts\guiinstaller\build.xml

launch-rc-server:[mkdir]创建dir:d:\checkouts\guiinstaller\report\run[echo]/k start java-jar lib/selenium-server-standalone-2.32.0.jar-port 4444

WaitForSeleniumServer:[waitfor]等待代理服务器启动

installcaps:[echo]${Test.classpath}[junit]DEBUG com.cordys.cm.uiunit.configuration-使用配置文件:“/c:/uiunit/uiunit.properties”(-2009166949)[junit]运行Test.cordyscapsinstallertest[junit]测试运行:1,失败:0,错误:1,跳过:0,经过的时间:0.191秒[junit]测试Test.cordyscapsinstallertest失败[junitreport]处理

shutdown-RC-server:[echo]seleniumserver是CIN400695:4444[java]RC运行在.........:4444是shutdown

生成成功总时间:17秒

在日志文件中我看到了下面的错误。

testcase classname="test.CordysCapsInstallerTest" name="initializationError0" time="0.007">
      <error type="java.lang.NullPointerException">java.lang.NullPointerException
at java.util.TreeMap.compare(TreeMap.java:1188)
at java.util.TreeMap.put(TreeMap.java:531)
at com.cordys.cm.uiunit.junit4.internal.runners.UIUnitClassMethodsRunner.getTestMethods(UIUnitClassMethodsRunner.java:168)
at com.cordys.cm.uiunit.junit4.internal.runners.UIUnitClassMethodsRunner.&lt;init&gt;(UIUnitClassMethodsRunner.java:45)
at com.cordys.cm.uiunit.junit4.runners.UIUnitRunner.&lt;init&gt;(UIUnitRunner.java:15)
at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
  </testcase>

共有1个答案

阚英武
2023-03-14

这种错误经常是由您的 Ant任务的类路径中的JAR以外的文件引起的。

Ant类路径只能包含:

  • JARS文件
  • 压缩文件
  • 目录
 类似资料:
  • 我正在 https://github.com/oracle/visualvm 构建这个项目。我的系统中有 JDK10。我将 build xml 中的源和目标选项从 1.5 更改为 1.8,因为有错误说 1.5 不再受支持。现在,我收到一个编译错误,指向common.xml它位于其他子文件夹中。 我不知道是怎么回事,因为错误日志也很模糊。此外,我第一次与Ant合作。 这是日志。 引发错误的通用部分.

  • 问题内容: 是否可以在Ant脚本中调用或执行Maven目标? 假设我有一个名为“ distribute”的蚂蚁目标,在其中我需要从另一个pom.xml调用一个Maven“编译”目标。 问题答案: 使用从Windows CLI运行Maven的exec任务的使用示例为:

  • 我已经有一个名为ant-jmeter-1.1.1的文件,位于路径 。 但是,当我从同一根目录运行ant命令时,出现了一个错误: BUILD 失败的 C:\apache-jmeter-2.13\apache-jmeter-2.13\extras\build.xml:87: 参考 C:\apache-jmeter-2.13\apache-jmeter-2.13\extras\ant-jmeter-1.

  • 目标是一个或多个任务的集合。 任务是一段代码,即将被执行。 构建文件包含一个项目,在项目内部声明了所有目标。 要创建目标,可以使用标记。 目标可以依赖于其他目标,并且依赖目标必须在当前目标之前执行。 例如,可能有两个目标:一个编译目标,另一个用于运行代码。 现在,只能在执行编译目标后运行目标。 因此运行目标取决于编译目标。 看下面一个例子。 调用顺序:编译(compile)-> 运行(run),表

  • 我试图使用ANT生成Eclipse Link JPA元模型 然而,我得到以下错误,这可能是什么原因? 错误的服务配置文件,或在构造处理器对象javax时引发异常。注释。处理。处理者:提供者组织。日食坚持不懈内部的jpa。modelgen。找不到CanonicalModelProcessor