I have a simple 'Hello World' command line Java application. I build the .jar from the command line - no IDE is used. I find that if the root directory is different (i.e., /hello/ vs. /hello/with/more/dirs/), the final .jar files are not exactly the same. (I compared the two with a Unix diff utility). It appears that the root directory is encoded into the .jar file.

Can anyone verify that is true?

Is there anything else encoded in the .jar file, such as timestamps?

Is there any way to prevent the path from being encoded?

1

Best Answer


A jar file is just a zip file (plus potentially a manifest). It contains the file list exactly like a zip file does. There is nothing you can do to prevent this.

If you don't want you files inside a directory in the jar, package it from the directory where you files reside. If you're more familiar with zip and don't need a manifest, you can just use that instead too.

There's a good overview of what a jar file actually is in the JAR file article on Wikipedia.