Each class has two classfiles in jar file

前端 未结 2 1668
青春惊慌失措
青春惊慌失措 2021-01-22 20:46

I have a jar file which has two class files per java file.

Java:

Foo.java
Bar.java

Classfile:

Foo.class
Foo.class
Bar.c         


        
相关标签:
2条回答
  • 2021-01-22 21:13

    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

    0 讨论(0)
  • 2021-01-22 21:29

    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!

    0 讨论(0)
提交回复
热议问题