How to Recover Source Code and Rebuild a Java WAR Project from Scratch
This guide walks through extracting Java source files from a deployed WAR package, decompiling the bytecode with free tools, and reorganizing the output into a Maven‑compatible web project structure so the application can be maintained and extended.
In this tutorial we assume a software development team faces a client‑driven change request but only has the deployed WAR file of a Java web application and no original source code.
The original application is built with Spring, exposes REST endpoints to generate PDF reports from MySQL data, and is packaged as a WAR.
Priority 1: Obtain the Application Source
First we retrieve the WAR file from the production server, rename it to .jar (since WAR and JAR are both ZIP‑based archives), and prepare it for decompilation.
Priority 2: WAR Reverse Engineering
Several free decompilers can turn Java bytecode back into source code, such as Bytecode Viewer, Java Decompiler, Fernflower, and Procyon. We chose Bytecode Viewer for its GUI and support for JAR inputs.
Using Bytecode Viewer we decompile the classes inside the renamed archive. The tool’s output is shown in the image below:
Priority 3: Restore the Web Application Structure
After decompilation we unpack the JAR to reveal the original directory layout. The expected structure includes:
WEB-INF
web.xml
lib (all dependency JARs)
classes
applicationContext.xml
log4j.properties
config.properties
com (package directories with .class files)
META-INF
MANIFEST.MF
maven
com.app
Application
pom.properties
pom.xml
images (form.png, img.png, other PNGs)
templates (HTML report templates)
index.jsp
We then map these files to a standard Maven web project layout:
src/main/java – all decompiled Java source files.
src/main/resources – configuration files such as applicationContext.xml, log4j.properties, and config.properties.
src/main/webapp – WEB-INF/web.xml, static images, HTML templates, and index.jsp.
Priority 4: Assemble the Project
With the source code and resources placed in the Maven directories, the project now contains the following structure:
src
main
java
com\... (all packages)
resources
applicationContext.xml
config.properties
log4j.properties
webapp
WEB-INF
web.xml
images
form.png
img.png
*.png
templates
*.html
index.jsp
pom.xmlRunning mvn clean install builds the application successfully.
Result
The recovered source code and rebuilt project were delivered to the client, enabling further maintenance and customization of the web application.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
21CTO
21CTO (21CTO.com) offers developers community, training, and services, making it your go‑to learning and service platform.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
