Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What exactly does a jar file contain?

Tags:

java

jar

As an intern, I use company code in my projects and they usually send me a jar file to work with. I add it to the build path in Eclipse and usually all is fine and dandy.

However, I got curious to know, what each class contained and when I try to open one of the classes in the jar file, it tells me that I need a source file.

What does this mean? I come from a C/C++ background so is a jar similar to an already compiled .o file and all I can see is the .h stuff? Or is there actual code in the jar file that I'm using that's encrypted so I can't read it?

Thanks for all the answers!

Edit:
Thanks, guys, I knew it was a sort of like an archive but I was confused to why when I tried to open the .class files, I got a bunch of random characters. The output was similar when I tried to open a .o file in C so I just wanted to make sure.
Thanks!

like image 748
joshualan Avatar asked Aug 22 '12 18:08

joshualan


People also ask

What does a JAR file contains?

The JAR file contains the TicTacToe class file and the audio and images directory, as expected. The output also shows that the JAR file contains a default manifest file, META-INF/MANIFEST. MF, which was automatically placed in the archive by the JAR tool.

What is the purpose of a JAR file?

A JAR file allows Java runtimes to efficiently deploy an entire application, including its classes and their associated resources, in a single request. JAR file elements may be compressed, shortening download times. A JAR file may contain a manifest file, that is located at META-INF/MANIFEST.

Does JAR file contain resources?

jar ) contain your executable classes and resource files. A jar can also contain other jar files, which is useful when your program needs some library which is packaged in a jar.

Does a JAR file contain libraries?

A library is a more abstract concept, in java, a library is usually packaged as a JAR (Java ARchive), or a collection of JARs. Show activity on this post. A jar file is zip archive containing among other files, the java class files. A Netbeans library contains resources required by the project, including jar files.


1 Answers

A JAR file is actually just a ZIP file. It can contain anything - usually it contains compiled Java code (*.class), but sometimes also Java sourcecode (*.java).

However, Java can be decompiled - in case the developer obfuscated his code you won't get any useful class/function/variable names though.

like image 126
ThiefMaster Avatar answered Oct 13 '22 23:10

ThiefMaster