'Each class has two classfiles in jar file
I have a jar file which has two class files per java file.
Java:
Foo.java
Bar.java
Classfile:
Foo.class
Foo.class
Bar.class
Bar.class
I have verified that there is only one java files per class. The java files do not any contain inner classes. I am using the ant jar-task to create the jar file. Before I execute the task, there is only one class file per class in the build directory.
I see the double class files with jar -tf jarfile.jar or when I view it in a zip program. When I unpack the files, the zip program asks if it should overwrite the existing file.
How can this happen?
Solution 1:[1]
Are you using the Ant Jar task? If so then you can most definitely get duplicate files in the same jar file. The duplicate attribute is used to stop that.
Please note that the zip format allows multiple files of the same fully-qualified name to exist within a single archive. This has been documented as causing various problems for unsuspecting users. If you wish to avoid this behavior you must set the duplicate attribute to a value other than its default, "add".
From the Ant Manual Page: http://ant.apache.org/manual/Tasks/jar.html
Solution 2:[2]
I got the same issue. I found out that just removing the fileset tag (a child tag of the jar tag) will make the final jar file not have 2 duplicate classes. As shown in the picture, just remove the fileset tag in the pink block. picture
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ken Brittain |
| Solution 2 | Chus |
