Ever wanted to run your Java applications in a lightweight, flexible, and powerful way? GlassFish, a robust and open-source application server, offers an “Embedded” version that’s perfect for the job. And now, it’s easier than ever to run applications with GlassFish directly from the command line or from a Docker container, as any standard Java application.
This video dives into the details of how you can leverage Embedded GlassFish to streamline your development and deployment process. Check out the video to see it in action!
What is Embedded GlassFish?
Embedded GlassFish is a lightweight version of the full GlassFish server. Historically it was designed to be started from within a Java application. But since GlassFish 7.0.18, you can also run it directly from the command line and configure it using command line arguments or a configuration file, with your applications in a separate WAR or EAR file. Just as you launch the Java VM with an application in a separate JAR file. This makes it incredibly versatile for a wide range of use cases, from microservices to testing.
Getting Started
Getting started is simple. You can download Embedded GlassFish from the official GlassFish website or include it in your project as a Maven artifact. Once you have it, you can run it as a standard Java application using the -jar argument:
java -jar glassfish-embedded-all.jar
To see all the available command-line options, you can use the --help argument.
Deploying Your Application
Deploying your application is as straightforward as adding the path to your application’s WAR or EAR file as an argument:
java -jar glassfish-embedded-all.jar /path/to/your/app.war
GlassFish will then print information about your application, including the URL where you can access it.
Configuration Made Easy
You have several options for configuring Embedded GlassFish to suit your needs.
Command-Line Options
For simple configurations, you can use command-line options. For example, to change the HTTP port, you can use the --port option:
java -jar glassfish-embedded-all.jar --port 8090
Configuration File
For more complex setups, you can use a properties file. By default, GlassFish looks for a file named glassfish.properties in the working directory. You can also specify a different file using a command-line argument.
In this file, you can specify all the command-line options as properties. For example, to set the port, you would add:
port=8090
You can also deploy applications using the configuration file. The property needs to start with deploy., followed by a name for your application, and the value is the path to your application. This even allows you to deploy multiple applications at once.
deploy.my-app=/path/to/your/app.war
Autodeployment
To simplify things even further, you can use the autodeploy folder. If you create an autodeploy folder in your working directory, GlassFish will automatically deploy any applications you place in it. This means you can add or remove applications without having to change your configuration file.
Conclusion
Running your applications with Embedded GlassFish from the command line is a powerful and flexible way to streamline your development and deployment workflow. With simple commands and flexible configuration options, you can get your applications up and running in no time. Watch our video to see a full demonstration and start taking advantage of Embedded GlassFish today!

