Using Embedded Glassfish with Maven
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>
- 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.
About the author:
Lincoln Baxter, III is the Chief Editor of Red Hat Developers, and has worked extensively on JBoss open-source projects; most notably as creator & project lead of JBoss Forge, author of Errai UI, and Project Lead of JBoss Windup. This content represents his personal opinions, not 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 the author of PrettyTime, social-style date and timestamp formatting for Java. When he is not swimming, running, or playing competitive Magic: The Gathering, Lincoln is focused on promoting open-source software and making technology more accessible for everyone.