Demo: 2. Modify the Class file
July 2025
Unzip a WAR file
Decompile class files using Procyon
Edit Java source directly and deploy (with expected errors)
Modify class files using a Java class editor (without recompiling) and deploy successfully
🧩 1. Unzip the WAR File
To inspect or modify the contents of a WAR file:
jar -xvf ../demo.warOr use any archive tool like 7-Zip or WinRAR to extract it.
🔍 2. Decompile Class Files Using Procyon
Procyon is a powerful Java decompiler. To use it:
Download the Procyon CLI jar from GitHub.
Run the decompiler:
java -jar procyon-decompiler.jar Demo2App.class > Demo2App.java
⚠️ 3. Directly Edit Class File and Deploy (With Errors)
If you edit the Java .class file directly and try to repackage and deploy without recompiling:
Modify the
.javafile (e.g., change the message inDemo2App.getMessage()).Repackage the WAR (without compiling):
jar -cvf demo.war *Deploy to Tomcat by copying the WAR to the
webapps/folder.
🛑 This will fail because Tomcat runs .class files, and your .java edits are ignored unless recompiled.

🛠️ 4. Edit Using a Java Class Editor (Without Recompiling)
To modify behaviour without source code or recompilation:
Use a bytecode editor like:
Open
Demo2App.classLocate the incorrect URL

Modify the return string in the bytecode.
Save the
.classfile and repackage the WAR:
jar -cvf Demo.war *Deploy to Tomcat again — this time it works without compilation errors.
The problem is fixed
Last updated
Was this helpful?