Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

eclipse

jar

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.

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.

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

Cheers

like image 848
Martin Preusse Avatar asked Dec 07 '10 15:12

Martin Preusse


People also ask

How do I export a Java project as runnable jar in eclipse?

To export your project, right-click it and select Export. Select Java > Runnable JAR file as the export destination and click Next. On the next page, specify the name and path of the JAR file to create and select the Launch configuration that includes the project name and the name of the test class.

Can we import jar file in eclipse?

Drag the jar file into the project folder in Eclipse. The jar file will now show up in the project. 2. Right click on the project after you have added the jar and select Properties.

How do I export a JAR file with resources?

Either from the context menu or from the menu bar's File menu, select Export. Expand the Java node and select JAR file. Click Next. In the JAR File Specification page, select the resources that you want to export in the Select the resources to export field.


2 Answers

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.


OLD-Answer

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

like image 180
Kevin D Avatar answered Sep 22 '22 10:09

Kevin D


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.

like image 26
Vladimir Ivanov Avatar answered Sep 21 '22 10:09

Vladimir Ivanov