Using ProGuard for Java Code Obfuscation in Maven Projects
This article explains how to protect Java applications from decompilation by configuring a ProGuard file and adding the ProGuard Maven plugin, then building the project to generate an obfuscated JAR, complete with step‑by‑step instructions and sample configuration code.
Compilation turns .java files into .class files, while decompilation can reverse .class back to source code, often using JD‑GUI.
To prevent easy decompilation, code obfuscation can be applied; this article demonstrates using ProGuard.
First, create a proguard.cfg file in the project root with options such as -target 1.8, -dontshrink, -dontoptimize, -dontusemixedcaseclassnames, -useuniqueclassmembernames, -adaptclassstrings, -keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,*Annotation*,EnclosingMethod, -keepnames interface ** { *; }, -keepparameternames, -keepclassmembers enum * { *; }, and various -keepclassmembers for Spring annotations, plus -ignorewarnings, -dontnote, -printconfiguration, and a -keep rule for the main application class.
Second, add the ProGuard Maven plugin to the <build> section of pom.xml with configuration specifying the input and output JAR, enabling obfuscation, including the proguard.cfg , library paths, filters, output directory, and any additional options.
After configuring, running mvn package builds the project, applies ProGuard, and produces an obfuscated JAR, which can be verified by the displayed build output and resulting JAR file.
Java Architect Essentials
Committed to sharing quality articles and tutorials to help Java programmers progress from junior to mid-level to senior architect. We curate high-quality learning resources, interview questions, videos, and projects from across the internet to help you systematically improve your Java architecture skills. Follow and reply '1024' to get Java programming resources. Learn together, grow together.
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.