Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do these two jar files with identical contents have different file sizes?

Tags:

java

jar

I am reorganizing our java code base and wanted to compare our resultant jar files.

When I build in the old source tree, I get a jar file size of 3360081.

In the new source tree it is 3360128.

I do a "jar tvf jarfile" and then strip the dates out of the file.

The listing looks like this:

     0 Mon Mar 16 10:41:16 EDT 2009 META-INF/
   102 Mon Mar 16 10:41:14 EDT 2009 META-INF/MANIFEST.MF
     0 Mon Mar 16 10:41:14 EDT 2009 decodes/

After I strip the dates, the listing looks like this:

     0  META-INF/
   102  META-INF/MANIFEST.MF
     0  decodes/

The two jar listings are identical.

What would cause a 47 byte difference in "identical" jar files?

I am running the compile on RedHat Linux 4.

like image 316
Mel Avatar asked Mar 16 '09 15:03

Mel


People also ask

Is it possible to compare two jar files?

Jarcomp is a comparison tool for Jar files and Zip files. It's free and cross-platform. If you have two jar files or two zip files, it will show you what the differences are in the contents. It shows which files have been added, which have been removed, and which are present in both archives.

How can I find the difference between two jars?

If you want to compare two zip files, you can use Java native libraries like ZipEntry. Or you can use any 3rd party utilities like Apache. You can get the list of files in one jar file and see if all the files are present in the other jar file. This way you will know the delta of the two jar files.

What happens if we put two different versions of jar files in classpath?

There is only a conflict if both jars define the exact same fully qualified class names. The JVM will most definitely load both jars - but it will not load classes from them that are already loaded.

What is the contents of a JAR file?

A Java Archive, or JAR file, contains all of the various components that make up a self-contained, executable Java application, deployable Java applet or, most commonly, a Java library to which any Java Runtime Environment can link.


2 Answers

File modification times of the compiled files are most probably the reason. Also, your class files might actually be different. If you reorganized your package structure they most definitely will.

like image 136
Bombe Avatar answered Sep 21 '22 14:09

Bombe


It's probably not the case - but by any chance are you using different compiler versions (even minor version differences) while compiling the two source bases?

like image 25
talonx Avatar answered Sep 25 '22 14:09

talonx