Martin Preusse Martin Preusse - 4 months ago 29
Java Question

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

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

Answer

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