--Generate source code from JAR file with JD-GUI of Java Decompiler project --This environment: macOS Catalina + Java 11 (AdoptOpenJDK 11.0.6)
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.
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 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
Drag and drop the jar file to convert it to Java source code.
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
*/
Recommended Posts