Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runnable Glassfish Embedded #25146

Merged

Conversation

OndroMih
Copy link
Contributor

@OndroMih OndroMih commented Sep 17, 2024

Allows running GlassFish Embedded from command line: java -jar glassfish-embedded.jar

Supports configuration via command line arguments and/or config files in the current directory:

  • set HTTP port
  • deploy applications passed as arguments
  • run arbitrary AsAdmin commands at boot

All GlassFish Embedded flavors are supported:

  • Standalone glassfish-embedded-all.jar, glassfish-embedded-web.jar, and glassfish-embedded-nucleus.jar
  • glassfish-embedded-static-shell.jar in the GlassFish Server installation

Includes fixes that made GlassFish Embedded Web usable. Includes fixes to the Static shell to make it equal to standalone GlassFish Embedded JAR files.

java -jar glassfish-embedded.jar --help prints the following info: glassfish.man.txt

Demo:

Runnable.GlassFish.Embedded.demo.mp4

Example of running an app from command line:

java -jar glassfish-embedded-all.jar "set configs.config.server-config.network-config.network-listeners.network-listener.http-listener.enabled=true" "set configs.config.server-config.network-config.network-listeners.network-listener.http-listener.port=8080" app.war

Example with root context:

java -jar glassfish-embedded-all.jar "set configs.config.server-config.network-config.network-listeners.network-listener.http-listener.enabled=true" "set configs.config.server-config.network-config.network-listeners.network-listener.http-listener.port=8080" "deploy --contextroot=/ app.war"
Deploy app if the argument is a file or dir.
If it's a single app, deploy to root context.
Support --option=value arguments with values that set GlassFish properties
Support several special options, like --port, --properties.
Support loading properties from glassfish.properties in the current directory.

Revert using FallbackStartupModule, was needed only for testing
Refactoring the API, so that UberMain can be configured and executed programmatically.
Like:

Refactored to the kernel module which already contains the config-api dependency.
Adding config-api to the bootstrap module caused a dependency cycle that failed the Maven build.
Add some missing dependencies that are outside of the default directory.

This makes Static shell equal to GF Embedded - it can be added to
the classpath or used as an executable JAR instead of GF Embedded JAR.

Fix WebSockets in GF Static Shell
Added missing Jakarta APIs:
- Validation is part of Web Profile
- XML Binding is not part of Web Profile but JobManagerService depends on it

Improvements in handling exceptions and logging messages.

final int MAX_LINE_LENGTH;
final String HELP_LINE_INDENT;
int characterCount;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather have it as local.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This must be an instance field, not a local variable. It holds the state. I refactored this class into a direct collector. That should make it clear it's a stateful class and shouldn't be reused.

Turned WordWraper into a direct collector WordWrapCollector.
Moved the man page into the proper module and location.
INFO level for output from admin commands
@OndroMih OndroMih force-pushed the ondromih-runnable-glassfish-embedded branch from 027fa29 to a66fb8c Compare September 17, 2024 11:23
Logger.getAnonymousLogger().severe("Ignoring unrecognized element "+in.getLocalName() + " at " + in.getLocation());
logger.log(Level.WARNING, () -> "Ignoring unrecognized element " + in.getLocalName() + " at line #" + in.getLocation().getLineNumber());
logger.log(Level.FINE, () -> "Unrecognized element " + in.getLocalName() + " at "
+ in.getLocation().toString().replace("\n", ", "));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if it is good to manipulate the location toString here, but ... or I will say it. It is wrong, but I have found that EventLocation (jaxb-osgi) really prints \n character after every value ... perhaps we could create a PR for them ;-)

Example of running an app from command line:

java -jar glassfish-embedded-all.jar "set configs.config.server-config.network-config.network-listeners.network-listener.http-listener.enabled=true" "set configs.config.server-config.network-config.network-listeners.network-listener.http-listener.port=8080" app.war

Example with root context:

java -jar glassfish-embedded-all.jar "set configs.config.server-config.network-config.network-listeners.network-listener.http-listener.enabled=true" "set configs.config.server-config.network-config.network-listeners.network-listener.http-listener.port=8080" "deploy --contextroot=/ app.war"
Deploy app if the argument is a file or dir.
If it's a single app, deploy to root context.
Support --option=value arguments with values that set GlassFish properties
Support several special options, like --port, --properties.
Support loading properties from glassfish.properties in the current directory.

Revert using FallbackStartupModule, was needed only for testing
Refactoring the API, so that UberMain can be configured and executed programmatically.
Like:

Refactored to the kernel module which already contains the config-api dependency.
Adding config-api to the bootstrap module caused a dependency cycle that failed the Maven build.
Add some missing dependencies that are outside of the default directory.

This makes Static shell equal to GF Embedded - it can be added to
the classpath or used as an executable JAR instead of GF Embedded JAR.

Fix WebSockets in GF Static Shell
Added missing Jakarta APIs:
- Validation is part of Web Profile
- XML Binding is not part of Web Profile but JobManagerService depends on it

Improvements in handling exceptions and logging messages.
Turned WordWraper into a direct collector WordWrapCollector.
Moved the man page into the proper module and location.
INFO level for output from admin commands
setLogLevel(logLevel, arguments);
}
},
LOG_PROPERTIES("logProperties", "--logProperties=FILE",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will cause issues, because JDK loads first and also starts using the logging configuration, the only reliable option is to use -Djava.util.logging.config.file on command line.

for (Handler handler : rootLogger.getHandlers()) {
handler.setLevel(level);
}
LogManager.getLogManager().getLoggerNames().asIterator()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Problem with this is that it returns just already initialized loggers. It would be better to retrieve current configuration from the logmanager, change it, and then call logManager.readConfiguration. Or just provide our own defaults generated using this parameter, set the root logger+handler level and just call logger.readConfiguration asap, even before main (in static init). It would be done just if user would not explicitly set the -Djava.util.logging.config.file or -Djava.util.logging.config.class.

In the video it seems that currently it uses JDK defaults.

@dmatej dmatej force-pushed the ondromih-runnable-glassfish-embedded branch from a66fb8c to 283d261 Compare September 20, 2024 22:10
@dmatej dmatej added this to the 7.0.18 milestone Sep 20, 2024
@dmatej
Copy link
Contributor

dmatej commented Sep 20, 2024

I have rebased the branch and resolved conflicts as it was conflicting with my changes in master - finally they were just minor.

@dmatej dmatej added the New feature A major new user functionality was added label Sep 20, 2024
@dmatej dmatej requested a review from a team September 20, 2024 22:11
@dmatej dmatej requested a review from a team September 20, 2024 22:17
…glassfish-embedded

# Conflicts:
#	nucleus/core/kernel/src/main/java/org/glassfish/runnablejar/UberMain.java
These match the configuration in the default GlassFish server domain.xml. 
With this it's no longer needed to specify --add-opens and --add-exports on the command line.
@dmatej dmatej merged commit c17a013 into eclipse-ee4j:master Sep 23, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
New feature A major new user functionality was added
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants