
March 23rd, 2010 by

Lincoln Baxter III
Using Embedded Glassfish with Maven
Three steps to add Embedded GlassFish to any existing project POM.
The
Embedded Glassfish project is hosted on
java.net, and as it is described, is very simple: “This project develops APIs and tools around “embedded GlassFish v3″. Embedded GFv3 is a delivery vehicle of GFv3 so that applications and tools can use GFv3 just as a library, inside their JVM, instead of having GFv3 as the overload of the entire JVM process. (And no, embedded GFv3 is not meant to be run on JavaME.)”
1. You’ll need to add this plugin repository to your POM:
<pluginRepositories>
<pluginRepository>
<id>Glassfish</id>
<url>http://download.java.net/maven/glassfish/</url>
</pluginRepository>
</pluginRepositories> |
<pluginRepositories>
<pluginRepository>
<id>Glassfish</id>
<url>http://download.java.net/maven/glassfish/</url>
</pluginRepository>
</pluginRepositories>
2. Then add the following plugin to your POM:
<build>
<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>
</build> |
<build>
<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>
</build>
3. Commands
- 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.
Reference:
http://blogs.sun.com/sirajg/entry/using_maven_plugin_for_v3
Posted in
Java, OpenSource
Looks simple enough for sure! So how can I run unit tests against this embedded glassfish? Or is that where Arquillian comes in?
That’s where Arquillian comes in 🙂
Arquillian Examples:
http://community.jboss.org/docs/DOC-14496
Glad I got you started on a new post.
This works ok but here’s a few observations.
It requires a war, so you have to say
mvn package embedded-glassfish:run
I see that the config element has as a child. Would this be the way to run exploded?
The only way I can tell how to set up a datasource is like this in the config element.
${basedir}/domain.xml
Is there an easier way?
To run Selenium during integration tests you have to do a bit more with the executions. Like this (for just the gf part. you have to add similar executions for Selenium):
start-glassfish
pre-integration-test
start
glassfish-deploy
pre-integration-test
deploy
glassfish-undeploy
post-integration-test
undeploy
stop-glassfish
post-integration-test
stop
And finally this should be in a profile; especially since you’re about to do a JBoss one right?
It would be nice if this plugin were better documented.
your blog eats XML – as you can tell by the executions.
The config child I meant was
instanceRoot in regard to running exploded
Actually you can also wrap the text in
(just one closing /, had to prevent the nested pre tag from being stripped 😉
If you re-post your comment in a ‘pre’ tag, I’ll fix this one.
Yeah, you have to URLencode it. Sorry. I should really add a warning. I don’t really have too much insight on embedded glassfish, since I mostly use JBoss AS6 right now.
I just went, found a blog, got it working, and posted it.
Test
I know that you are the main developer of the Seam faces module.
Could you explain how to setup a good integration test for JSF using Arquillian?
For example, I’d like to test what happen when the client requests “/home.jsf?id=3”.
For what you know, is actually possible?
Hi!
I couldn’t get work JSPs hot-swapping. What are the main points to take into consideration?
Here is my configuration
Configured as stated in your post but when executing "mvn -e clean install" then maven throws a LifecycleExecutionException with caused by: java.io.FileNotFoundException: test.war. Looking on the file system the war-file "test.war" wasn’t even created. If I change to version 3.1 then no exception is thrown but
> PlainTextActionReporterFAILUREFile not found : /Users/grudom/Daten/IDE/EclipseProjects/workspace/transact/test.war06.09.2012 09:18:03 PluginUtil doDeploy
> INFO: Deployed null
Why is no war file being generated?