CLI Reference

The examples here use the p4j command that the installer provides. On Windows the GUI is installed from the .exe, and on macOS from Protector4J.app inside the .dmg; how the GUI was installed does not change the CLI syntax below. If the installer did not put the CLI on your PATH, run it from the command-line entry point 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 low-level encode also works with the command name left out:

p4j input.jar output.p4jx [options]

Launch-level options choose the packaging target. They can go before the command name, or together at the very end of the command line — the command line the GUI exports uses the trailing form.

OptionDescription
--java-version <N>The Java line to bundle with the package: 8, 11, 17, 21, or 25. Default 21.
--target-platform <id>[,<id>...]One or more target platforms, comma-separated or by repeating the option. Defaults to the current platform.
--create-new-folderCreate a new p4jx-xxxxxxxx subdirectory inside the output directory. Applies to javaapp, springboot, and tomcat only.

For example:

p4j --java-version 21 --target-platform linux-x64 springboot app.jar dist
p4j springboot app.jar dist --java-version 21 --target-platform linux-x64

These two commands are equivalent. Launch-level options cannot be mixed in among the packager options — there they are read as unknown packager options and the command fails.

2. Common options

OptionDescription
--jre-home <path>Derive keys from the given final P4JX JRE runtime. The higher-level packaging commands also copy this runtime.
--keys <keys.json>Use an explicit private key file. For diagnostics and internal processes only — never ship it with the application.
--no-jitKeep protected methods out of the JIT and run them in the interpreter.
--zip-overlay off|scannerTurn the scanner ZIP compatibility view off or on. Default off.
--compat-scanScan and exit; no output argument is needed.
--compat-applyScan, apply the conservative recommendations, then continue encoding.
--no-compat-excludesUsed with --compat-apply: do not add the recommended exclusions automatically.
--native-compat jxbrowserFor javaapp and springboot only: request access for the bundled JxBrowser. The version, platform, and five-layer hash are still verified in full, and no other value, path, or hash is accepted.
--account-email <email>Licensed account email address
--account-password <password>Licensed account password
--app-id <id>Application identifier
--license-expires-in <sec>Requested trial lifetime in seconds, subject to server policy

Supported by the higher-level packaging commands:

OptionDescription
--archive-suffix p4jx|jarSuffix of the generated archive, default p4jx. It does not change the internal format.
--jvm-option <option>Writes the option into the macOS, Linux, and Windows startup scripts. Use one option per flag and repeat the flag as needed. When the Windows EXE is enabled, the same options are embedded in the EXE.

3. encode

p4j encode input.jar output.p4jx [options]
OptionDescription
--bind-launcher <jar>Compute and bind the SHA-256 of the launcher JAR
--launcher-sha256 <hex>Supply the launcher SHA-256 directly, for advanced integrations
--runtime-major <N>Target for the resource view and multi-release flattening. Default 21.

--bind-launcher and --launcher-sha256 cannot be used together.

4. javaapp

p4j javaapp input.jar output-dir [options]
OptionDescription
--main <class>The main class to start
--protect <rules>Comma-separated rules for the classes and packages to protect. All classes by default.
--exclude <rules>Rules for what to leave out of the protection scope
--javafx [<dir>]Enable JavaFX, optionally from a local component directory
--javafx-webviewAlways include WebView
--no-javafx-webviewNever include WebView
--no-javafxExplicitly disable JavaFX
--native-compat jxbrowserWrite ATTACH_THREAD for the JxBrowser IPC libraries that fully match the bundled directory. Java 17, 21, and 25 only.

5. springboot

p4j springboot input.jar output-dir [options]
OptionDescription
--main <class>The Spring Boot main class. Read from the manifest by default.
--protect <rules>Protect the matching classes in BOOT-INF/classes
--exclude <rules>Leave the matching classes or packages unprotected
--protect-lib <globs>Protect the matching JARs in BOOT-INF/lib, comma-separated
--layout p4jx-fat|fat|separateOutput layout, default p4jx-fat
--javafx [<dir>]Enable JavaFX, optionally from a local component directory
--javafx-webviewAlways include WebView
--no-javafx-webviewNever include WebView
--no-javafxExplicitly disable JavaFX
--native-compat jxbrowserAs for javaapp; the same scanner covers the nested BOOT-INF/lib.

6. tomcat

p4j tomcat input.war output-dir [options]
OptionDescription
--exclude <rules>Leave the matching classes or packages in WEB-INF/classes unprotected
--context </path>Context path, default /app
--append-appAdd the application to an existing P4JX Tomcat package
--tomcat-version auto|9|10Detect automatically or force a version. Default auto on the CLI.
--precompile-jspForce JSP precompilation
--no-precompile-jspTurn JSP precompilation off

7. Windows EXE options

javaapp, springboot, and tomcat can build an additional native Windows launcher. The target platforms must include windows-x64, windows-x86, or windows-aarch64.

OptionDescription
--windows-exeBuild a Windows application EXE. Nothing is built without it.
--exe-name <name>EXE file name; defaults to the input file name, or tomcat for tomcat packages
--exe-mode <mode>console (default) or gui
--exe-icon <ico>Optional Windows icon, in .ico format
--exe-file-version <a.b.c.d>PE file version: one to four numbers, each 0–65535. Empty means 0.0.0.0.
--exe-product-version <a.b.c.d>PE product version, same rules
--exe-company <text>Company name
--exe-product <text>Product name
--exe-description <text>File description
--exe-copyright <text>Copyright notice

Any --exe-* option turns on EXE generation by itself. In a multi-platform task, only the Windows packages get an EXE; the others are built as usual and keep their startup scripts.

p4j --target-platform windows-x64 javaapp app.jar dist --windows-exe --exe-name MyApp.exe --exe-mode gui

For the full instructions, runtime behavior, and code signing steps, see Create a Windows EXE Launcher.

8. Rule syntax

com.example.SecretService   a single class
com.example.service         this package only
com.example.service.*       this package only
com.example.service.**      this package and all its sub-packages
com/example/Secret.class    a class entry path

Separate several rules with commas. Quote any rule containing * so the shell does not expand it:

--protect 'com.example.**' --exclude 'com.example.dto.**,com.example.config.**'

9. Environment variables

Environment variables suit shared defaults for a CI job, a container, or several commands run in sequence. When you need a single packaging run to be recorded and reproducible, pass the values explicitly as CLI options instead.

VariableCLI equivalentDescription
P4JX_RUNTIME_JAVA_VERSION--java-version <N>The Java line for higher-level packaging: 8, 11, 17, 21, or 25
P4JX_RUNTIME_PLATFORM--target-platform <id>A single target platform. Use the CLI option to package several platforms at once.
P4JX_RUNTIME_CACHE_DIRnoneOverride the VLX JRE download cache directory
APP_JAVA_OPTScompare --jvm-optionAdd JVM options for one run of the generated application. --jvm-option bakes options into the startup script at packaging time, so the two are not equivalent.

When a variable and its CLI option are both set, the explicit CLI option wins. The environment variables remain fully supported, so existing automation scripts keep working.

For example, to set a common target for several packaging commands in the current shell:

export P4JX_RUNTIME_JAVA_VERSION=21
export P4JX_RUNTIME_PLATFORM=linux-x64

p4j springboot service-a.jar release/service-a
p4j springboot service-b.jar release/service-b

The Java system property equivalents suit advanced cases where you launch the packager JAR directly:

-Dp4jx.runtime.java.version=<N>
-Dp4jx.runtime.platform=<platform>
-Dp4jx.runtime.cache.dir=<dir>

10. Automation example

p4j --java-version 21 \
  --target-platform linux-x64 \
  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 the automatic recommendations. Record the final options, the SHA-256 of the input, and the tool version as part of your release provenance.

For GUI and CLI examples, and for editing run.sh, run.bat, the Tomcat startup scripts, and Windows PowerShell, see JVM Startup Options.