Thursday Dec 10, 2009

Using maven plugin for v3 embedded glassfish

The final version of Glassfish V3 is now available for download. It contains an embedded API that allows users to to create a customized, integrated solution within a single JVM.

One of the ways the embedded feature could be used is through maven. A maven plugin exists specifically for embedded glassfish. It allows a simple way to use the various embedded features.

Following are the maven goals supported by the plugin :

embedded-glasfish:run - starts the embedded server if it is not already running and deploys the specfied application. The goal keeps the server running, so the user can make changes in the application, reploy and test iteratively.

embedded-glassfish:start - starts the embedded server with the specified parameters

embedded-glassfish:deploy - deploys the specified application

embedded-glassfish:undeploy - undeploys the application identified by the "name" parameter. If no name is specifed all applications are undeployed.

embedded-glassfish:stop - stops the embedded server

embedded-glassfish:admin - executes the specified admin command on the embedded server. For example, you could create a jdbc resource.

A sample pom.xml snippet that would execute the run goal :


<plugins>
<plugin>
<groupId>org.glassfish</groupId>
<artifactId>maven-embedded-glassfish-plugin</artifactId>
<version>3.0</version>
<configuration>
<goalPrefix>glassfish</goalPrefix>
<app>test.war</app>
<port>8080</port>
<contextRoot>test</contextRoot>
</configuration>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>run</goal
</goals>
</execution>
</executions>
</plugin>
</plugins>

Friday Sep 04, 2009

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();

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