Skip to content

Don't pass removed -Djava.endorsed.dirs when running app clients#9446

Open
renatsaf wants to merge 1 commit into
apache:masterfrom
renatsaf:issue-6270-appclient-endorsed-dirs
Open

Don't pass removed -Djava.endorsed.dirs when running app clients#9446
renatsaf wants to merge 1 commit into
apache:masterfrom
renatsaf:issue-6270-appclient-endorsed-dirs

Conversation

@renatsaf

Copy link
Copy Markdown

What

When running a Jakarta EE application client against a registered GlassFish server, the run fails immediately because the spawned JVM cannot be created:

-Djava.endorsed.dirs=/Applications/glassfish7/glassfish/lib/endorsed:/Applications/glassfish7/glassfish/modules/endorsed is not supported. ...
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

The deploy succeeds; only the client JVM launch fails, every time.

Root cause

Hk2JavaEEPlatformImpl.getToolProperty(TOOL_APP_CLIENT_RUNTIME, TOOL_PROP_JVM_OPTS) always prepended -Djava.endorsed.dirs=<root>/lib/endorsed:<root>/modules/endorsed to the app-client container JVM options. This value ends up in the generated build-impl.xml via j2ee.appclient.tool.jvmoptions and is passed as a <jvmarg> to the run-appclient macro.

The endorsed-standards mechanism was removed in JDK 9 (JEP 220), and HotSpot deliberately aborts at startup when java.endorsed.dirs is set. GlassFish 7 requires JDK 11+ and ships no endorsed directories at all, so the option is both invalid and pointing at non-existent paths.

Fix

Build -Djava.endorsed.dirs only from the lib/endorsed / modules/endorsed directories that actually exist, and omit the option entirely when neither is present. This lets app clients run on JDK 9+ (modern GlassFish), while preserving behavior for legacy servers on JDK 8 that still ship those directories.

Notes

  • The Payara plugin (payara.jakartaee) carries the same forked code; left out of this PR to keep it focused on the reported GlassFish case, but it should get the same treatment in a follow-up.

Fixes #6270

When running a Jakarta EE application client against a registered
GlassFish server, the GlassFish plugin built the app-client container
JVM options by always prepending
-Djava.endorsed.dirs=<root>/lib/endorsed:<root>/modules/endorsed.

The endorsed-standards mechanism was removed in JDK 9 (JEP 220), and
HotSpot deliberately aborts at startup when java.endorsed.dirs is set:

    -Djava.endorsed.dirs=... is not supported. ...
    Error: Could not create the Java Virtual Machine.

GlassFish 7 requires JDK 11+ and ships no endorsed directories, so the
app client run failed every time with no way to recover from the IDE.

Build the option only from the lib/endorsed and modules/endorsed
directories that actually exist, and omit -Djava.endorsed.dirs entirely
when neither is present. This fixes running app clients on JDK 9+ while
preserving behavior for legacy servers on JDK 8 that still ship those
directories.

Fixes apache#6270
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enterprise [ci] enable enterprise job Java EE/Jakarta EE [ci] enable enterprise job

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Can't run Java enterprise application client against glassfish 7.0.6 server because VM won't create because of -Djava.endorsed.dirs

2 participants