使用 Eclipse 将 Java 项目导出到 JAR 时出现“重复条目”错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4378074/
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-08-14 16:43:04  来源:igfitidea点击:

"duplicate entry" error when exporting Java project to JAR with Eclipse

javaeclipsejar

提问by Martin Preusse

I am trying to exort a Java project with Eclipse 3.6.1 to a runnable Jar. This used to work properly but failed today, afer I added some additional Jars to my class path.

我正在尝试将带有 Eclipse 3.6.1 的 Java 项目导出到可运行的 Jar。这曾经可以正常工作但今天失败了,因为我在我的类路径中添加了一些额外的 Jars。

The error is

错误是

duplicate entry: some/class.class

Interestingly, there is a duplicate entry for almost any class in my buildpath. Even though I did not change anything. The Jars I added do not contain duplicate classes.

有趣的是,我的构建路径中几乎所有类都有一个重复条目。即使我没有改变任何东西。我添加的 Jars 不包含重复的类。

Question: Is this some kind of Eclipse bug? Am I ovrlooking something obvious? Does anybody have an idea what could cause this error?

问题:这是某种 Eclipse 错误吗?我在看一些明显的东西吗?有没有人知道可能导致此错误的原因?

Cheers

干杯

采纳答案by Kevin D

You could try modifying the line

您可以尝试修改该行

<jar destfile="/Volumes/resi/talosBase.jar" filesetmanifest="mergewithoutmain">

in your build file to be

在您的构建文件中

<jar destfile="/Volumes/resi/talosBase.jar" filesetmanifest="mergewithoutmain" duplicate="preserve">

This will cause ant to preserve the first entry of any duplicate and ignore the rest. The default behavious is "add" so you can end up with multiple files of the same fully qualified name. The other valid entry for this paramter is "fail" but I don't think that will help you here.

这将导致 ant 保留任何重复项的第一个条目并忽略其余条目。默认行为是“添加”,因此您最终可以得到多个具有相同完全限定名称的文件。此参数的另一个有效条目是“失败”,但我认为这对您没有帮助。



OLD-Answer

旧答案

Delete your last created runnable jar either manually or alter the generated ant script to do so before creating a new one

手动删除上次创建的可运行 jar 或更改生成的 ant 脚本,然后再创建新的 jar

回答by Vladimir Ivanov

Cleaning the project should help. It is not eclipse bug, but rather jar maker's one. Apparantly, it takes the classes and see that such classes already exist and can't understand that it should replace them instead of adding.

清理项目应该会有所帮助。这不是 Eclipse 错误,而是 jar 制造商的错误。显然,它接受类并看到这些类已经存在并且无法理解它应该替换它们而不是添加它们。

回答by Gaurav Gupta

Cleaning the project will help you.

清理项目将对您有所帮助。

回答by Aarish Ramesh

Try removing the jars and adding it once again.. this got the error resolved for me..

尝试移除罐子并再次添加它..这为我解决了错误..

回答by sysuser

I too had the same problem, but then I slightly modified the build settings in Eclipse to the one mentioned below.

我也遇到了同样的问题,但后来我将 Eclipse 中的构建设置稍微修改为下面提到的那个。

Eclipse export jar

Eclipse 导出 jar

This solved the duplicate entry issue for me, it just copies all required jars to a subdirectory.

这为我解决了重复输入问题,它只是将所有必需的 jar 复制到子目录中。

回答by forest forest

in my case cleaning the project doesnt change any thing so i use a workaround :

在我的情况下,清理项目不会改变任何事情,所以我使用了一种解决方法:

  1. genearte a build script by activation by save ANT script ant script genration
  2. execute the ant script manually or in eclipse (its better) executing script by eclipse
  1. 通过保存 ANT 脚本ant 脚本生成激活生成构建脚本
  2. 手动或在 eclipse 中执行 ant 脚本(它更好) 通过 eclipse 执行脚本

and I change my ant build script by adding option as indicate in this post duplicate="preserve" (to keep the first version on the duplicated file )

并且我通过添加选项来更改我的 ant 构建脚本,如本文中所指示的

hope it help

希望它有帮助