Using Embedded GlassFish APIs

We have been making good progress on the embedded GlasFish for the V3 final release.

Here I will talk a bit about some of the basic embedded APIs that you can use.

The org.glassfish.api.embedded.Server object lets you perform lifecycle operations on the embedded server. It can be configured using the corresponding Builder object. For example :

// get the server builder
Server.Builder builder = new Server.Builder("test");

If you have a a preconfigured domain.xml that you want to use, you can do something like this :
// get the builder for EmbeddedFileSystem
EmbeddedFileSystem.Builder efsb = new EmbeddedFileSystem.Builder();
// specify the domain.xml location
efsb.configurationFile("myExistingdomain.xml");
EmbeddedFileSystem efs = efsb.build();
builder.embeddedFileSystem(efs);

You could also specify the install root of the server and the instance(or domain) root to the EmbeddedFileSystem.Builder. For example, you can specify the installRoot using
efsb.installRoot("installRootDirectory", true);

Then create the server object
Server server = builder.build();
You don't have to specify the EmbeddedFileSystem - if you don't specify it a temporary file system would be created automatically and used.
You can then specify the containers that you want to use. For example for web container,
ContainerBuilder b = server.getConfig(ContainerBuilder.Type.web);
server.addContainer(b);
You can also specify the port that you want to use. For example,
server.createPort(8989);
server.start();


The next interesting thing to do would be to deploy applications to it. For example, if you are deploying a packaged web app, hello.war, you can do this :
EmbeddedDeployer deployer = server.getDeployer();
DeployCommandParameters cmdParams = new DeployCommandParameters();
cmdParams.name = "appname";
cmdParams.contextRoot = "hello";

deployer.deploy("hello.war", cmdParams);

Now your application is running on the embedded server.

You can undeploy like this :
deployer.undeploy("appname");
To stop the server,
server.stop();

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
About

sirajg

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today