CLI Parameter Reference
The examples in this document use the p4j command provided after installation. The Windows GUI is installed via .exe, while the macOS GUI is installed through Protector4J.app within .dmg; the installation method of the GUI does not change the CLI syntax below. If the installer does not include the CLI in PATH, run it from the command-line entry point provided in the Protector4J installation directory.
p4j --help
1. Commands
p4j encode <input.jar> <output.p4jx|output.jar> [options]
p4j javaapp <input.jar> <output-dir> [options]
p4j springboot <input.jar> <output-dir> [options]
p4j tomcat <input.war> <output-dir> [options]
The lower-level encode also allows the command name to be omitted:
p4j input.jar output.p4jx [options]
2. General Options
| Options | Description |
|---|---|
--no-jit | Disable the JIT protection method and switch to interpreter execution. |
--zip-overlay off|scanner | Turn off or attach the ZIP compatibility scanner view; the default is off. |
--compat-scan | Scan only and exit; no output parameters are required. |
--compat-apply | Scan, apply conservative suggestions, and then continue with encoding. |
--no-compat-excludes | Used in conjunction with --compat-apply; do not automatically add the suggested exclusion classes. |
--account-email <email> | License account email. |
--account-password <password> | License account password. |
--app-id <id> | Specified application identifier |
--license-expires-in <sec> | Requests the number of valid seconds for the trial, which is constrained by server policies |
High-level packaging commands supported:
| Options | Description |
|---|---|
--archive-suffix p4jx|jar | The file suffix for the generated archive, default is p4jx; the internal format remains unchanged |
--jvm-option <option> | Writes startup scripts for macOS/Linux and Windows; each parameter is used once but can be repeated |
3. encode
p4j encode input.jar output.p4jx [options]
| Options | Description |
|---|---|
--runtime-major <N> | Specify the resource view/Multi-Release flattening target, default is 21 |
4. javaapp
p4j javaapp input.jar output-dir [options]
| Options | Description |
|---|---|
--main <class> | Specify the main class for launching |
--protect <rules> | Rules for classes/packages to be under protection, separated by commas; all classes are applied by default. |
--exclude <rules> | Exclude from the protection scope. |
--javafx [<dir>] | Enable JavaFX; optional local asset directory. |
--javafx-webview | Force inclusion of WebView. |
--no-javafx-webview | Force exclusion of WebView. |
--no-javafx | Explicitly disable JavaFX. |
5. springboot
p4j springboot input.jar output-dir [options]
| Options. | Description. |
|---|---|
--main <class> | Specify the Spring Boot main class; reads the Manifest by default |
--protect <rules> | Provide protection for matching classes in BOOT-INF/classes |
--exclude <rules> | Exclude classes or packages |
--protect-lib <globs> | Protect matching BOOT-INF/lib JAR files, separated by commas |
--layout p4jx-fat|fat|separate | Output layout, default is p4jx-fat |
--javafx [<dir>] | Enable JavaFX; optional local asset directory |
--javafx-webview | Force inclusion of WebView |
--no-javafx-webview | Force exclusion of WebView |
--no-javafx | Explicitly disable JavaFX |
6. tomcat
p4j tomcat input.war output-dir [options]
| Options | Description |
|---|---|
--exclude <rules> | Exclude classes or packages from WEB-INF/classes |
--context </path> | Context path, default is /app |
--append-app | Add the application to an existing P4JX Tomcat package |
--tomcat-version auto|9|10 | Automatically detect or force a version, CLI default is auto |
--precompile-jsp | Force precompilation of JSPs |
--no-precompile-jsp | Pre-compilation of JSPs is prohibited. |
7. Rule syntax.
com.example.SecretService Single class
com.example.service Direct package matching
com.example.service.* Direct package matching
com.example.service.** Package and all sub-packages
com/example/Secret.class class entry path
Separate multiple rules with commas; quotes should be used when * is included in a shell script.
--protect 'com.example.**' --exclude 'com.example.dto.**,com.example.config.**'
8. Environment variables.
| Variables. | Description. |
|---|---|
P4JX_RUNTIME_JAVA_VERSION | Java training lines used for high-level packaging: 8/11/17/21/25. |
P4JX_RUNTIME_PLATFORM | Target platform ID. |
P4JX_RUNTIME_CACHE_DIR | VLX JRE download cache directory |
APP_JAVA_OPTS | Temporarily add JVM parameters when running the generated application; supported on macOS/Linux and Windows. |
System property equivalents for Java are suitable for advanced scenarios where the encoder JAR needs to be started directly.
-Dp4jx.runtime.java.version=<N>
-Dp4jx.runtime.platform=<platform>
-Dp4jx.runtime.cache.dir=<dir>
9. Automation examples
P4JX_RUNTIME_JAVA_VERSION=21 \
P4JX_RUNTIME_PLATFORM=linux-x64 \
p4j springboot build/app.jar release/linux-x64 \
--compat-apply \
--protect 'com.example.service.impl.**' \
--exclude 'com.example.dto.**,com.example.config.**' \
--jvm-option -Xms1g \
--jvm-option -Xmx2g \
--app-id com.example.app
Explicit protection/exclusion and layout options override automatic suggestions. It is recommended to record the final parameters, input SHA-256, and tool version as part of the release provenance.
GUI, CLI, direct editing of run.sh/run.bat, Tomcat startup scripts, and Windows PowerShell examples are available in JVM startup parameters configuration.