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

OptionsDescription
--no-jitDisable the JIT protection method and switch to interpreter execution.
--zip-overlay off|scannerTurn off or attach the ZIP compatibility scanner view; the default is off.
--compat-scanScan only and exit; no output parameters are required.
--compat-applyScan, apply conservative suggestions, and then continue with encoding.
--no-compat-excludesUsed 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:

OptionsDescription
--archive-suffix p4jx|jarThe 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]
OptionsDescription
--runtime-major <N>Specify the resource view/Multi-Release flattening target, default is 21

4. javaapp

p4j javaapp input.jar output-dir [options]
OptionsDescription
--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-webviewForce inclusion of WebView.
--no-javafx-webviewForce exclusion of WebView.
--no-javafxExplicitly 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|separateOutput layout, default is p4jx-fat
--javafx [<dir>]Enable JavaFX; optional local asset directory
--javafx-webviewForce inclusion of WebView
--no-javafx-webviewForce exclusion of WebView
--no-javafxExplicitly disable JavaFX

6. tomcat

p4j tomcat input.war output-dir [options]
OptionsDescription
--exclude <rules>Exclude classes or packages from WEB-INF/classes
--context </path>Context path, default is /app
--append-appAdd the application to an existing P4JX Tomcat package
--tomcat-version auto|9|10Automatically detect or force a version, CLI default is auto
--precompile-jspForce precompilation of JSPs
--no-precompile-jspPre-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_VERSIONJava training lines used for high-level packaging: 8/11/17/21/25.
P4JX_RUNTIME_PLATFORMTarget platform ID.
P4JX_RUNTIME_CACHE_DIRVLX JRE download cache directory
APP_JAVA_OPTSTemporarily 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.