Search code examples
javabuildjar

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

  • I think I found the problem. This is the jar task:

        <jar basedir="${build.class.dir}" jarfile="${dist.dir}/${subproject}.jar">
            <fileset dir="${build.class.dir}" />
        </jar>
    

    As I read in the Ant website

    This task forms an implicit FileSet and supports most attributes of (dir becomes >basedir) as well as the nested , and elements.

    So it would seem that either the tag or basedir is uneccessary. At least it works.fine if I comment out the fileset tag.

    Thanks for your help and pointers!