Generate source code from JAR file with JD-GUI of Java Decompiler project

Overview

--Generate source code from JAR file with JD-GUI of Java Decompiler project --This environment: macOS Catalina + Java 11 (AdoptOpenJDK 11.0.6)

What is JD-GUI?

A decompiler that generates Java source code from class and JAR files. It also supports annotations, generics, enums, etc. introduced in Java 5 and later.

Java Decompiler

JD-Core is a library that reconstructs Java source code from one or more “.class” files. JD-Core may be used to recover lost source code and explore the source of Java runtime libraries. New features of Java 5, such as annotations, generics or type “enum”, are supported. JD-GUI and JD-Eclipse include JD-Core library.

Download and run

Download jd-gui-1.6.6.jar from the official website Java Decompiler.

$ wget https://github.com/java-decompiler/jd-gui/releases/download/v1.6.6/jd-gui-1.6.6.jar

Start JD-GUI with the java command.

$ java -jar jd-gui-1.6.6.jar 
jd1.png

Drag and drop the jar file to convert it to Java source code.

jd2.png

You can generate a zip file that summarizes the source code by selecting File → Save All Sources from the menu.

Try unzipping the generated zip file.

$ unzip helloworldmod-1.2.3.jar.src.zip 
Archive:  helloworldmod-1.2.3.jar.src.zip
   creating: META-INF/
  inflating: META-INF/MANIFEST.MF    
  inflating: META-INF/mods.toml      
   creating: com/
   creating: com/example/
  inflating: com/example/HelloWorldMod.java  
  inflating: pack.mcmeta             

In the generated source code, the path where the jar file was located is embedded with comments.

$ cat com/example/HelloWorldMod.java
/*    */ package com.example;
/*    */ 
/*    */ import net.minecraft.entity.player.PlayerEntity;
/*    */ import net.minecraft.util.math.BlockPos;
/*    */ import net.minecraft.util.text.ITextComponent;
/*    */ import net.minecraft.util.text.StringTextComponent;
/*    */ import net.minecraftforge.common.MinecraftForge;
/*    */ import net.minecraftforge.event.entity.player.PlayerEvent;
/*    */ import net.minecraftforge.eventbus.api.SubscribeEvent;
/*    */ import net.minecraftforge.fml.common.Mod;
/*    */ 
/*    */ 
/*    */ @Mod("helloworldmod")
/*    */ public class HelloWorldMod
/*    */ {
/*    */   public HelloWorldMod() {
/* 17 */     MinecraftForge.EVENT_BUS.register(this);
/*    */   }
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */   
/*    */   @SubscribeEvent
/*    */   public void onPlayerLoggedIn(PlayerEvent.PlayerLoggedInEvent event) {
/* 28 */     PlayerEntity player = event.getPlayer();
/* 29 */     BlockPos pos = player.func_180425_c();
/*    */ 
/*    */ 
/*    */     
/* 33 */     String message = "Hello, World!\n[name]=[" + player.func_200200_C_().func_150254_d() + "]\n[pos]=[" + pos.func_177958_n() + "," + pos.func_177956_o() + "," + pos.func_177952_p() + "]";
/* 34 */     StringTextComponent stringTextComponent = new StringTextComponent(message);
/* 35 */     player.func_145747_a((ITextComponent)stringTextComponent);
/*    */   }
/*    */ }


/* Location:              /Users/johndoe/hello/build/libs/helloworldmod-1.2.3.jar!/com/example/HelloWorldMod.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */

Reference material

Recommended Posts

Generate source code from JAR file with JD-GUI of Java Decompiler project
Generate HashMap from XML resource file
Generate source code from JAR file with JD-GUI of Java Decompiler project
[Spring] Read a message from a YAML file with MessageSource
How to decompile apk file to java source code with MAC
Code Java from Emacs with Eclim
Basic structure of Java source code
Execute Java code from cpp with cocos2dx
Comparison of Alibaba's open source Sentinel Java flow control project with Hystrix
[Java] Get MimeType from the contents of the file with Apathce Tika [Kotlin]
JAVA: jar, aar, view the contents of the file
[Java] Explanation of Strategy pattern (with sample code)
Clean up findViewById from source code with DataBindingLibrary
Create a Jar file with two lines of command
Include image in jar file with java static method
[Java] Get the file in the jar regardless of the environment
java (split source file)
Eval Java source from Java
Specify the character code of the source when building with Maven
Generate Stream from an array of primitive types in Java
Sample of using Salesforce's Bulk API from Java client with PK-chunking
How to open a script file from Ubuntu with VS code
What I learned from doing Java work with Visual Studio Code
Overwrite upload of file with the same name with BOX SDK (java)
[Gradle] Build a Java project with a configuration different from the convention