GlassFish Server Open Source Edition 3.1 - Embedded One Pager
Embedded Glassfish 1.2. Name(s) and e-mail address of Document Author(s)/Supplier:
05/19/2010 2. Project Summary |
Profile | Jar Name | Size | Dependencies | Download Location | Description |
---|---|---|---|---|---|
full | glassfish-embedded-all.jar | about 60 MB | pom.xml | download | Meant for users interested in the full set of features supported by embedded |
web | glassfish-embedded-web.jar | about 35 MB | pom.xml | download | Meant for users of the web profile |
nucleus | glassfish-embedded-nucleus.jar | about 5 MB | pom.xml | download | Corresponds to the nucleus distribution. Most users would need to add further packages to do something meaningful. |
The complete application+runtime bundle can then be deployed using a variety of deployment mechanisms - for example, using maven, an installer, zip or even Java Web Start.
In both the implanted and autonomous modes, a custom domain.xml can be specified.
The embedded API provides convenient methods to control the life cycle of the embedded server and to deploy applications to it.
This is the common import statement for all the code snippets below:
import org.glassfish.embeddable.GlassFish; import org.glassfish.embeddable.GlassFishProperties; import org.glassfish.embeddable.GlassFishRuntime; import org.glassfish.embeddable.web.Context; import org.glassfish.embeddable.web.HttpListener; import org.glassfish.embeddable.web.VirtualServer; import org.glassfish.embeddable.web.WebContainer; import org.glassfish.embeddable.web.WebListener;
A sample piece of code that binds the web container to a specific port and deploys a packaged .war to the embedded server.
// Create a Embedded GlassFish instance to listen at 9090 http port GlassFishProperties glassfishProperties = new GlassFishProperties(); glassfishProperties.setPort("http-listener", 9090); GlassFish glassfish = GlassFishRuntime.bootstrap().newGlassFish(glassfishProperties); // Start Embedded GlassFish glassfish.start(); // Deploy an application to the Embedded GlassFish Deployer deployer = glassfish.getDeployer(); String appName = deployer.deploy(new File("hello.war"), "--contextroot=hello", "--name=app1"); // Undeploy the application deployer.undeploy(appName); // Stop Embedded GlassFish glassfish.stop(); // Dispose Embedded GlassFish. This will clean up any temporary file system created by Embedded GlassFish glassfish.dispose();
Sample of using embedded server with an existing domain.xml. Any custom port configuration can be done in the domain.xml that is passed in here.
// Create a Embedded GlassFish instance using a preconfigured domain.xml GlassFishProperties glassfishProperties = new GlassFishProperties(); glassfishProperties.setConfigFileURI(new File("myExistingdomain.xml").toURI().toString()); // this is the only change to the above code. GlassFish glassfish = GlassFishRuntime.bootstrap().newGlassFish(glassfishProperties); // Start Embedded GlassFish glassfish.start(); // Deploy an application to the Embedded GlassFish Deployer deployer = glassfish.getDeployer(); String appName = deployer.deploy(new File("hello.war"), "--contextroot=hello", "--name=app1"); // Undeploy the application deployer.undeploy(appName); // Stop Embedded GlassFish glassfish.stop(); // Dispose Embedded GlassFish. This will clean up any temporary file system created by Embedded GlassFish glassfish.dispose();
Scattered Archive sample :
// Create a Embedded GlassFish instance to listen at 9090 http port GlassFishProperties glassfishProperties = new GlassFishProperties(); glassfishProperties.setPort("http-listener", 9090); GlassFish glassfish = GlassFishRuntime.bootstrap().newGlassFish(glassfishProperties); // Start Embedded GlassFish glassfish.start(); // Deploy a scattered application to the Embedded GlassFish Deployer deployer = glassfish.getDeployer(); // Build a scattered web archive. ScatteredArchive archive = new ScatteredArchive("testapp", ScatteredArchive.Type.WAR); // target/classes directory contains my complied servlets archive.addClassPath(new File("target", "classes")); // resources/sun-web.xml is my WEB-INF/sun-web.xml archive.addMetadata(new File("resources", "sun-web.xml")); // resources/web.xml is my WEB-INF/web.xml archive.addMetadata(new File("resources", "web.xml")); // Deploy the scattered web archive. String appName = deployer.deploy(archive.toURI(), "--contextroot=hello"); // Undeploy the scattered web application deployer.undeploy(appName); // Stop Embedded GlassFish glassfish.stop(); // Dispose Embedded GlassFish. This will clean up any temporary file system created by Embedded GlassFish glassfish.dispose();
Sample of using embedded web API to create an application context and add a http listener for it.
// Create a Embedded GlassFish instance which listens at 9090 http port GlassFishProperties glassfishProperties = new GlassFishProperties(); glassfishProperties.setPort("http-listener", 9090); GlassFish glassfish = GlassFishRuntime.bootstrap().newGlassFish(glassfishProperties); // Start Embedded GlassFish glassfish.start(); /* Create an application context and a http listener */ // Get WebContainer service WebContainer webContainer = glassfish.getService(WebContainer.class); // Create a http listener to listen at port 9292 and add it to the web container. HttpListener httpListener = webContainer.createWebListener( "test-listener", HttpListener.class); httpListener.setPort(9292); webContainer.addWebListener(httpListener); // Create a web application context Context context = webContainer.createContext(new File("/tmp/hello-app")); webContainer.addContext(context, "hello"); // With that, you can access http://localhost:9292/hello // Stop Embedded GlassFish glassfish.stop(); // Dispose Embedded GlassFish. This will clean up any temporary file system created by Embedded GlassFish glassfish.dispose();
3.0 introduced a maven plugin that allows users to start, stop and configure the server and to deploy and undeploy applications. Following are the various goals supported by the plugin. The artifactID for the plugin is glassfish-embedded-maven-plugin. The various parameters used in different goals are summarized below :
Name | Optional | Default | Description |
---|---|---|---|
app | No | None | Location of packaged application or application directory. |
serverID | Yes | "maven" | id of server. one could work with multiple embedded servers. |
containerType | Yes | "all" | container to start("web", ejb", "jpa", "all"). |
installRoot | Yes | temporary directory | root directory of already installed server, if using an already existing install. |
instanceRoot | Yes | temporary directory | directory of the instance of already installed server, if using an already existing install. |
configFile | Yes | packaged domain.xml at core/kernel/src/main/resources/org/glassfish/embed/domain.xml | location of domain.xml. |
port | yes | if no configFile and port are specified, 8080 | |
name | yes | default deployment value | name of application. |
contextRoot | yes | default deployment value | Applicable for web applications. |
precompileJsp | yes | default deployment value | boolean |
dbVendorName | yes | default deployment value | |
createTables | yes | default deployment value | boolean |
dropTables | yes | default deployment value | boolean |
cascade | yes | default undeployment value | |
autoDelete | yes | true | temporary directory will be deleted when server is stopped. If temporary directory was not created and a pre-existing directory was pointed to, this is ignored. |
Following is a summary for the various plugin goals :
• embedded-glassfish:run
The goal will start the server, deploy the application and will keep running. The user can chose to redeploy while the plugin is running, if changes are made to the application. It is interactive - when the user presses "Enter" on console the application is redeployed.
Parameters :
app, serverID, containerType, installRoot, instanceRoot, configFile, port, name, contextRoot, precompileJsp, dbVendorName, createTables, dropTables, autoDelete.
• embedded-glassfish:start
This will start the embedded server with specified container(s)
Parameters :
serverID, installRoot, instanceRoot, configFile, port, containerType, autoDelete
• embedded-glassfish:deploy
Parameters :
Deploys the specified archive to the embedded server.
serverID, name, app, contextRoot , precompileJsp, createTables, dbVendorName, createTables
• embedded-glassfish:undeploy
Parameters :
serverID, name, dropTables, cascade - if no name is specifed all applications will be undeployed.
• embedded-glassfish:stop
serverID
• embedded-glassfish:admin
Runs appserver administration commands in embedded. Either command+commandParameters or commandLine should be specified.
Name | Optional | Default | Description |
---|---|---|---|
serverID | Yes | "maven" | ID of server to run the command on |
command | if commandLine is specified this is ignored and is not necessary | None | Name of asadmin command |
commandParameters | Yes. if commandLine is specified this is ignored | None | Map of command parameters |
commandLine | if command is specified this is not necessary | None | asadmin style commandline. |
3.1 will also support ant tasks for embedded. These are expected to be mostly used for running dev tests in embedded mode. Following is a summary of the tasks :
• glassfish-embedded-start :
serverID, port, installRoot, instanceRoot, configFile, containerType, autoDelete.
• glassfish-embedded-stop :
serverID
• glassfish-embedded-deploy :
name, app, contextRoot , precompileJsp, createTables, dbVendorName, createTables
• glassfish-embedded-undeploy :
serverID, name, cascade
• glassfish-embedded-admin :
serverID, command, commandParameters, commandLine
P1-P3 bugs in the embedded category filed in issuetracker will be addressed.
Priority would be given to technologies related to web profile, since that appears to be the more relevant to most users.
Clustering will not be supported in embedded mode.
Interfaces may be commands, files, directory structure, ports,
DTD/Schema, tools, APIs, CLIs, etc.
Note: In lieu of listing the interfaces in the one pager, providing
a link to another specification which defines the interfaces
is acceptable.
List new, public interfaces this project exports.
None identified at this time.
None identified at this time
Embedded API usage and maven plugin will need to be documented
None
Identify changes to GUIs, CLI, agents, plugins...
None
None
Some user visible messages will need to be localized.
What impact will this proposal have on product installation?
None
No impact on upgrade and migration.
None
None
Existing dev tests from various components will be used to test embedded. These tests will run in an optional embedded mode. Priority will be given to running web dev tests.
Milestone 7. Refer to the Milestone Planning Document for more details.