Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read a class file from an extracted jar file?

I want to read a .class file that is located inside of a .jar package. How can I read a readable .class file from a .jar package?

My environment is:

  • Language version: Java
  • Platform version: Java 1.8.0_73
  • Runtime: Java(TM) SE Runtime Environment (build 1.8.0_73-b02)
  • VM Server: Java HotSpot(TM) 64-Bit Server VM (build 25.73-b02, mixed mode)
  • Operating system: Windows 10 Home (64-bit) [build 10586]

EDIT:

My extracted .class file that contains binary & compiled bytecode:

The .class file contains binary & compiled bytecode

The output I want:

The .java file - readable code

like image 806
Suriyaa Avatar asked Jun 19 '16 11:06

Suriyaa


People also ask

How do I view the class in a jar file?

Using the unzip Command The unzip command is a commonly used utility for working with ZIP files from the Linux command-line. Thanks to the unzip command, we can view the content of a JAR file without the JDK. The output above is pretty clear. It lists the files in the JAR file in a tabular format.

How do I view the contents of a class file?

Using javap The Java command-line comes with the javap tool that displays information about the fields, constructors, and methods of a class file. Based on the options used, it can disassemble a class and show the instructions that comprise the Java bytecode.


1 Answers

Use a decompiler. I prefer using Fernflower, or if you use IntelliJ IDEA, simply open .class files from there, because it has Fernflower pre-installed.

Or, go to javadecompilers.com, upload your .jar file, use CFR and download the decompiled .zip file.

However, in some cases, decompiling code is quite illegal, so, prefer to learn instead of decompiling.

like image 90
RoccoDev Avatar answered Oct 15 '22 11:10

RoccoDev