Using Embedded Glassfish with Maven
Lincoln Baxter III
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>
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>
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
|
About the author:Lincoln Baxter, III is a Senior Software Engineer at Red Hat, working on JBoss open-source projects; most notably as project lead for JBoss Forge. This blog represents his personal thoughts and perspectives, not necessarily those of his employer. He is a founder of OCPsoft, the author of PrettyFaces and Rewrite, the leading URL-rewriting extensions for Servlet, Java EE, and Java web frameworks; he is also a member of the JavaServer™ Faces Expert Group. When he is not swimming, running, or playing Ultimate Frisbee, Lincoln is focused on promoting open-source software and making web-applications more accessible for small businesses, individuals. His latest project is SocialPM, an open-source, agile project management tool. |
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
org.glassfish maven-embedded-glassfish-plugin 3.0.1 ${project.build.directory} embedded-glassfish target/myapp.war 8080 myapp true