每个类在jar文件中都有两个类文件(Each class has two classfiles in jar file)

系统教程 行业动态 更新时间:2024-06-14 16:57:18
每个类在jar文件中都有两个类文件(Each class has two classfiles in jar file)

我有一个jar文件,每个java文件有两个类文件。

Java的:

Foo.java Bar.java

类文件:

Foo.class Foo.class Bar.class Bar.class

我已经验证每个类只有一个java文件。 java文件不包含任何内部类。 我正在使用ant jar-task来创建jar文件。 在执行任务之前,构建目录中每个类只有一个类文件。

我看到带有jar -tf jarfile.jar的双类文件,或者当我在zip程序中查看它时。 当我解压缩文件时,zip程序会询问它是否应该覆盖现有文件。

怎么会发生这种情况?

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?

最满意答案

你在使用Ant Jar任务吗? 如果是这样,那么你绝对可以在同一个jar文件中获得重复文件。 duplicate属性用于停止它。

请注意,zip格式允许在同一个存档中存在多个具有相同完全限定名称的文件。 这已被证明为不知情的用户造成各种问题。 如果您希望避免此行为,则必须将duplicate属性设置为默认值“add”以外的值。

来自Ant手册页: http : //ant.apache.org/manual/Tasks/jar.html

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!

更多推荐

本文发布于:2023-04-12 20:27:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/fdba3eedf471ee07496127c462b926b4.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   中都   有两个   jar   classfiles

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!