eclipse Ant 构建类路径 jar 生成“打开 zip 文件时出错”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2601364/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 14:36:21  来源:igfitidea点击:

Ant build classpath jar generates "error in opening zip file"

eclipseantbuildzip

提问by Alastair Brayne

I have a project built in eclipse with a dependencies on 3rd party jars. I'm trying to generate a suitable build file for ant - using eclipses built-in export->ant buildfile feature as a starting block.

我有一个在 Eclipse 中构建的项目,它依赖于 3rd 方 jars。我正在尝试为 ant 生成一个合适的构建文件 - 使用 eclipses 内置导出->ant 构建文件功能作为起始块。

When I run the build target I get the following error:

当我运行构建目标时,出现以下错误:

[javac] error: error reading /base/repo/FabTrace/lib/apache/geronimo/specs/geronimo-j2ee-management_1.0_spec/1.0/geronimo-j2ee-management_1.0_spec-1.0.jar; error in opening zip file

And the whole build file (auto-generated by eclipse) looks like this: (NB: the error above always references the first jar listed in the classpath)

整个构建文件(由 eclipse 自动生成)如下所示:(注意:上面的错误总是引用类路径中列出的第一个 jar)

<project basedir="." default="build" name="FabTrace">
    <property environment="env"/>
    <property name="ECLIPSE_HOME" value="/opt/apps/eclipse"/>
    <property name="debuglevel" value="source,lines,vars"/>
    <property name="target" value="1.5"/>
    <property name="source" value="1.5"/>
    <path id="JUnit 4.libraryclasspath">
        <pathelement location="${ECLIPSE_HOME}/plugins/org.junit4_4.5.0.v20090824/junit.jar"/>
        <pathelement location="${ECLIPSE_HOME}/plugins/org.hamcrest.core_1.1.0.v20090501071000.jar"/>
    </path>
    <path id="FabTrace.classpath">
        <pathelement location="bin"/>
        <pathelement location="lib/apache/geronimo/specs/geronimo-j2ee-management_1.0_spec/1.0/geronimo-j2ee-management_1.0_spec-1.0.jar"/>
        <pathelement location="lib/apache/geronimo/specs/geronimo-jms_1.1_spec/1.0/geronimo-jms_1.1_spec-1.0.jar"/>
        <pathelement location="lib/commons-collections/commons-collections/3.2/commons-collections-3.2.jar"/>
        <pathelement location="lib/commons-io/commons-io/1.4/commons-io-1.4.jar"/>
        <pathelement location="lib/commons-lang/commons-lang/2.1/commons-lang-2.1.jar"/>
        <pathelement location="lib/commons-logging/commons-logging/1.1/commons-logging-1.1.jar"/>
        <pathelement location="lib/commons-logging/commons-logging-api/1.1/commons-logging-api-1.1.jar"/>
        <pathelement location="lib/javax/activation/activation/1.1/activation-1.1.jar"/>
        <pathelement location="lib/javax/jms/jms/1.1/jms-1.1.jar"/>
        <pathelement location="lib/javax/mail/mail/1.4/mail-1.4.jar"/>
        <pathelement location="lib/javax/xml/bind/jaxb-api/2.1/jaxb-api-2.1.jar"/>
        <pathelement location="lib/javax/xml/stream/stax-api/1.0-2/stax-api-1.0-2.jar"/>
        <pathelement location="lib/junit/junit/4.4/junit-4.4.jar"/>
        <pathelement location="lib/log4j/log4j/1.2.15/log4j-1.2.15.jar"/>
        <pathelement location="lib/apache/camel/camel-jms-2.0-M1.jar"/>
        <pathelement location="lib/spring/spring-2.5.6.jar"/>
        <pathelement location="lib/apache/camel/camel-bundle-2.0-M1.jar"/>
        <pathelement location="lib/backport-util-concurrent/backport-util-concurrent-3.1.jar"/>
        <pathelement location="lib/commons-pool/commons-pool-1.4.jar"/>
        <pathelement location="lib/apache/camel/camel-activemq-1.1.0.jar"/>
        <pathelement location="lib/apache/activemq/activemq-camel-5.2.0.jar"/>
        <pathelement location="lib/jencks/jencks-2.2-all.jar"/>
        <pathelement location="lib/jencks/jencks-amqpool-2.2.jar"/>
        <pathelement location="lib/activemq/apache-activemq-5.3.1/activemq-all-5.3.1.jar"/>
        <pathelement location="lib/activemq/apache-activemq-5.3.1/lib/optional/xbean-spring-3.6.jar"/>
        <pathelement location="lib/activemq/apache-activemq-5.3.1/lib/activemq-core-5.3.1.jar"/>
        <pathelement location="lib/activemq/apache-activemq-5.3.1/lib/camel-jetty-2.2.0.jar"/>
        <pathelement location="lib/activemq/apache-activemq-5.3.1/lib/web/jetty-6.1.9.jar"/>
        <pathelement location="lib/activemq/apache-activemq-5.3.1/lib/web/jetty-util-6.1.9.jar"/>
        <pathelement location="lib/activemq/apache-activemq-5.3.1/lib/web/jetty-xbean-6.1.9.jar"/>
        <pathelement location="lib/activemq/apache-activemq-5.3.1/lib/optional/activemq-optional-5.3.1.jar"/>
        <pathelement location="lib/activemq/apache-activemq-5.3.1/lib/web/geronimo-servlet_2.5_spec-1.2.jar"/>
        <pathelement location="lib/activemq/apache-activemq-5.3.1/lib/optional/spring-beans-2.5.6.jar"/>
        <pathelement location="lib/activemq/apache-activemq-5.3.1/lib/optional/spring-context-2.5.6.jar"/>
        <pathelement location="lib/activemq/apache-activemq-5.3.1/lib/optional/spring-core-2.5.6.jar"/>
        <path refid="JUnit 4.libraryclasspath"/>
    </path>
    <target name="init">
        <mkdir dir="bin"/>
        <copy includeemptydirs="false" todir="bin">
            <fileset dir="src/main/java">
                <exclude name="**/*.launch"/>
                <exclude name="**/*.java"/>
            </fileset>
        </copy>
        <copy includeemptydirs="false" todir="bin">
            <fileset dir="src/test/java">
                <exclude name="**/*.launch"/>
                <exclude name="**/*.java"/>
            </fileset>
        </copy>
        <copy includeemptydirs="false" todir="bin">
            <fileset dir="config">
                <exclude name="**/*.launch"/>
                <exclude name="**/*.java"/>
            </fileset>
        </copy>
    </target>
    <target name="clean">
        <delete dir="bin"/>
    </target>
    <target depends="clean" name="cleanall"/>
    <target depends="build-subprojects,build-project" name="build"/>
    <target name="build-subprojects"/>
    <target depends="init" name="build-project">
        <echo message="${ant.project.name}: ${ant.file}"/>
        <javac debug="true" debuglevel="${debuglevel}" destdir="bin" source="${source}" target="${target}">
            <src path="src/main/java"/>
            <classpath refid="FabTrace.classpath"/>
        </javac>
        <javac debug="true" debuglevel="${debuglevel}" destdir="bin" source="${source}" target="${target}">
            <src path="src/test/java"/>
            <classpath refid="FabTrace.classpath"/>
        </javac>
        <javac debug="true" debuglevel="${debuglevel}" destdir="bin" source="${source}" target="${target}">
            <src path="config"/>
            <classpath refid="FabTrace.classpath"/>
        </javac>
    </target>

</project>

(I know there's eclipse specific stuff in here. But I get the same results with or without it.)

(我知道这里有 eclipse 特定的东西。但无论有没有它,我都会得到相同的结果。)

I've done ye old google search and trawled around without success.

我已经完成了你的旧谷歌搜索,但没有成功。

I can confirm that all the jars do really exist. I've also tried from the commandline and as sudo - again, same results.

我可以确认所有的罐子确实存在。我也试过从命令行和 sudo - 同样,同样的结果。

Any help would be greatly appreciated.

任何帮助将不胜感激。

Cheers

干杯

采纳答案by Alastair Brayne

As per Martin Clayton's suggestions, my previous comment is copied below as an answer.

根据 Martin Clayton 的建议,我之前的评论复制在下面作为答案。

"Sigh. I'd figured that because I'd removed the first jars that originally caused this problem (I wasn't even convinced I really needed them any more) and the problem just moved to the next jar... well, that made me suspicious of a systemic fault. Turns out I did in fact have aload of garbage jars on the classpath. Must have screwed up a download or something at some point. Anyway, all fixed now. Cheers"

“唉。我想这是因为我已经移除了最初导致这个问题的第一个罐子(我什至不相信我真的需要它们了),问题只是转移到了下一个罐子......好吧,那个让我怀疑是系统故障。事实证明,我确实在类路径上确实有大量垃圾罐。一定是在某个时候搞砸了下载或其他什么。无论如何,现在都修复了。干杯”

回答by bakoyaro

Is there a <filterset/>in any of the copy statements in your build file? I ran into an issue once where I was <copy>-ing "**/*" and towards the end of development I figured out how to use <filterset/>with <copy>.

<filterset/>您的构建文件中是否有任何复制语句?有一次我在<copy>-ing " **/*" 的地方遇到了一个问题,在开发结束时我想出了如何使用<filterset/>with <copy>.

To make a long story short, the text replacement worked flawlessly, however any binary file, executable or .jar that was in that "**/*" path was totally destroyed. Instead of opening files in binary mode, they get opened in text mode, and then saved in text mode.

长话短说,文本替换完美无缺,但是该“ **/*”路径中的任何二进制文件、可执行文件或 .jar 都被完全破坏了。它们不是以二进制模式打开文件,而是以文本模式打开,然后以文本模式保存。

If you do have a <filterset/>, or something similar anywhere in your build file, make sure to <exclude/>any and all binary files.

如果您<filterset/>的构建文件中的任何地方确实有. 或类似的东西,请确保<exclude/>任何和所有二进制文件。