CLI Installation & Usage
The Shield Java CLI is a standalone command-line tool for obfuscating JAR files without the Gradle plugin. Use it for CI/CD pipelines, backend JVM applications, or any scenario where Gradle integration is not available.
Requirements
- Java 8 or higher (
java -versionto check) - A ByteHide project token
Installation
Download from Maven Central
curl -O https://repo1.maven.org/maven2/com/bytehide/shield/shield-java-cli/1.1.5/shield-java-cli-1.1.5.jarcurl -O https://repo1.maven.org/maven2/com/bytehide/shield/shield-java-cli/1.1.5/shield-java-cli-1.1.5.jarOr download manually from Maven Central.
Verify Installation
java -jar shield-java-cli-1.1.5.jar --version
# Output: 1.1.5
java -jar shield-java-cli-1.1.5.jar --helpjava -jar shield-java-cli-1.1.5.jar --version
# Output: 1.1.5
java -jar shield-java-cli-1.1.5.jar --helpUsage
1. Create a Configuration File
Create shield-config.json:
{
"projectToken": "your-bytehide-project-token",
"inputJars": ["my-app.jar"],
"outputJar": "my-app-protected.jar",
"protections": {
"StringEncryption": true,
"ConstantMutation": true,
"DebugInfoRemoval": true,
"NameObfuscation": true,
"ControlFlowMatrix": true
}
}{
"projectToken": "your-bytehide-project-token",
"inputJars": ["my-app.jar"],
"outputJar": "my-app-protected.jar",
"protections": {
"StringEncryption": true,
"ConstantMutation": true,
"DebugInfoRemoval": true,
"NameObfuscation": true,
"ControlFlowMatrix": true
}
}2. Run
java -jar shield-java-cli-1.1.5.jar -c shield-config.jsonjava -jar shield-java-cli-1.1.5.jar -c shield-config.jsonThe protected JAR will be written to the path specified in outputJar.
3. Verify
java -jar my-app-protected.jarjava -jar my-app-protected.jarCLI Options
| Option | Description |
|---|---|
-c, --config <file> | Configuration file (JSON) |
-i, --input <file> | Input JAR file (overrides config) |
-o, --output <file> | Output JAR file (overrides config) |
-m, --mapping <file> | Output mapping file for deobfuscation |
-v, --verbose | Verbose output |
-V, --version | Print version |
-h, --help | Show help |
JSON Configuration Reference
Full Example
{
"projectToken": "your-token",
"inputJars": ["app.jar"],
"outputJar": "app-protected.jar",
"libraryJars": [],
"mappingFile": "mapping.txt",
"protections": {
"StringEncryption": true,
"ConstantMutation": true,
"DebugInfoRemoval": true,
"NameObfuscation": true,
"ControlFlowMatrix": true,
"AntiDebug": false,
"AntiTamper": false,
"ReferenceProxy": false,
"ResourceProtection": false
},
"renameMode": "LETTERS",
"repackageClasses": true,
"repackageClassesTargetPackage": "a",
"excludedPackages": [
"com.example.models",
"com.example.api:NameObfuscation",
"com.example.legacy:StringEncryption,ConstantMutation"
],
"keepRules": [
{
"classPattern": "com/example/Main",
"memberPattern": "*",
"keepNames": true
}
],
"verbose": true
}{
"projectToken": "your-token",
"inputJars": ["app.jar"],
"outputJar": "app-protected.jar",
"libraryJars": [],
"mappingFile": "mapping.txt",
"protections": {
"StringEncryption": true,
"ConstantMutation": true,
"DebugInfoRemoval": true,
"NameObfuscation": true,
"ControlFlowMatrix": true,
"AntiDebug": false,
"AntiTamper": false,
"ReferenceProxy": false,
"ResourceProtection": false
},
"renameMode": "LETTERS",
"repackageClasses": true,
"repackageClassesTargetPackage": "a",
"excludedPackages": [
"com.example.models",
"com.example.api:NameObfuscation",
"com.example.legacy:StringEncryption,ConstantMutation"
],
"keepRules": [
{
"classPattern": "com/example/Main",
"memberPattern": "*",
"keepNames": true
}
],
"verbose": true
}Fields
| Field | Type | Default | Description |
|---|---|---|---|
inputJars | String[] | required | Input JAR files to obfuscate |
outputJar | String | required | Output obfuscated JAR path |
libraryJars | String[] | [] | Library JARs (not obfuscated, used for reference resolution) |
mappingFile | String | null | Output mapping file for deobfuscation |
projectToken | String | required | ByteHide project token |
protections | Object | — | Enable/disable individual protections |
renameMode | String | "LETTERS" | LETTERS, UNICODE, ASCII, SEQUENTIAL, DECODABLE, FAKE |
repackageClasses | Boolean | false | Flatten all classes into one package |
repackageClassesTargetPackage | String | "a" | Target package name |
keepRules | Object[] | [] | ProGuard-compatible keep rules |
excludedPackages | String[] | [] | Packages to exclude (global or per-protection) |
excludedClasses | String[] | [] | Specific classes to exclude |
excludedMethods | String[] | [] | Specific methods to exclude |
verbose | Boolean | false | Verbose output |
stringEncryptionMode | String | "DYNAMIC" | DYNAMIC or BASIC |
stringEncryptionMinLength | Int | 3 | Min string length to encrypt |
controlFlowConfig.intensity | Int | 5 | Control flow intensity (1-10) |
controlFlowConfig.depth | Int | 10 | Control flow depth (1-18) |
controlFlowConfig.mode | String | "MIXED" | SWITCH, JUMP, or MIXED |
aggressiveOverloading | Boolean | false | Reuse names for methods with different signatures |
allowAccessModification | Boolean | false | Widen access modifiers |
adaptClassStrings | Boolean | false | Adapt Class.forName("...") strings when renaming classes |
CLI vs Gradle plugin
In the CLI, all JARs listed in inputJars are treated as program classes and obfuscated. Use libraryJars for dependencies that should only be used for reference resolution (not obfuscated). The Gradle plugin handles this separation automatically.
Exclusions
Exclude packages from all protections:
"excludedPackages": ["com.example.models"]"excludedPackages": ["com.example.models"]Exclude packages from specific protections only:
"excludedPackages": ["com.example.api:NameObfuscation,StringEncryption"]"excludedPackages": ["com.example.api:NameObfuscation,StringEncryption"]Keep Rules
Preserve class/member names while still applying other protections:
"keepRules": [
{
"classPattern": "com/example/Main",
"memberPattern": "*",
"keepNames": true
}
]"keepRules": [
{
"classPattern": "com/example/Main",
"memberPattern": "*",
"keepNames": true
}
]Use "keepClassName": false to allow class renaming while preserving field/method names (useful for Gson/Jackson DTOs):
"keepRules": [
{
"classPattern": "com/example/dto/**",
"memberPattern": "*",
"keepNames": true,
"keepClassName": false
}
]"keepRules": [
{
"classPattern": "com/example/dto/**",
"memberPattern": "*",
"keepNames": true,
"keepClassName": false
}
]Examples
Obfuscate a Spring Boot JAR
{
"projectToken": "your-token",
"inputJars": ["target/myapp-1.0.0.jar"],
"outputJar": "target/myapp-1.0.0-protected.jar",
"protections": {
"StringEncryption": true,
"ConstantMutation": true,
"ControlFlowMatrix": true,
"DebugInfoRemoval": true
},
"excludedPackages": [
"org.springframework",
"com.fasterxml.jackson"
]
}{
"projectToken": "your-token",
"inputJars": ["target/myapp-1.0.0.jar"],
"outputJar": "target/myapp-1.0.0-protected.jar",
"protections": {
"StringEncryption": true,
"ConstantMutation": true,
"ControlFlowMatrix": true,
"DebugInfoRemoval": true
},
"excludedPackages": [
"org.springframework",
"com.fasterxml.jackson"
]
}Generate a Mapping File
java -jar shield-java-cli-1.1.5.jar -c shield-config.json -m mapping.txtjava -jar shield-java-cli-1.1.5.jar -c shield-config.json -m mapping.txtThe mapping file maps obfuscated names back to original names, useful for reading stack traces from production.
Related
- Gradle Setup — Gradle plugin integration (recommended for Android)
- Gradle DSL Reference — Complete Gradle configuration reference
- Deobfuscate Stack Traces — Using mapping files to decode crash reports