Stuff for build plugins section to let you run via “mvn embedded-glassfish:run” instead of via jetty:
While running [ENTER]
will redeploy, X[RETURN]
will quit.
<plugin>
<groupId>org.glassfish</groupId>
<artifactId>maven-embedded-glassfish-plugin</artifactId>
<version>3.0</version>
<configuration>
<goalPrefix>embedded-glassfish</goalPrefix>
<app>${basedir}/target/${project.build.finalName}.war</app>
<autoDelete>true</autoDelete>
<port>8080</port>
</configuration>
<executions>
<execution>
<id>start-glassfish</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>glassfish-deploy</id>
<phase>pre-integration-test</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
<execution>
<id>glassfish-undeploy</id>
<phase>post-integration-test</phase>
<goals>
<goal>undeploy</goal>
</goals>
</execution>
<execution>
<id>stop-glassfish</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1-beta-1</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
This is optional, but here are some dependencies for your pom.xml to allow you to run test code in the embedded glassfish container and use Derby as your test database (you can mooch of off _TimerPool in your persistence.xml …). This would be if you wanted to start the server automatically from your test code :
<dependency>
< groupId>org.glassfish.extras</groupId>
<artifactId>glassfish-embedded-all</artifactId>
<version>3.0</version>
<scope>test</scope>
</dependency>
<!--- THIS MUST BE AFTER THE glassfish-embedded DEPENDENCY.
The javaee6 API isn't really provided if its embedded. Yet if we remove the dependency below,
netbeans won't compile stuff.
-->
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<version>10.5.3.0_1</version>
</dependency>
This is a little more advanced. If you’re starting the server from test code, you may want be bootrapping a database as well each time, and don’t want to just mooch off of __TimerPool. Its settings for a domain.xml file to create a Derby in-memory database for testing with a corresponding persistence unit:
[code]
[/code]
<persistence-unit name="TestPU" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>jdbc/TestDS</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="eclipselink.target-database" value="Derby"/>
<property name="eclipselink.target-server" value="SunAS9"/>
<property name="eclipselink.logging.level" value="FINEST"/>
<property name="eclipselink.weaving" value="false"/>
<property name="eclipselink.weaving.eager" value="true"/>
<property name="eclipselink.weaving.internal" value="true"/>
<property name="eclipselink.weaving.changetracking" value="true"/>
<property name="eclipselink.jdbc.batch-writing" value="JDBC"/>
<property name="javax.persistence.validation.mode" value="AUTO"/>
<property name="eclipselink.ddl-generation" value="create-tables"/>
<property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver"/>
<property name="javax.persistence.jdbc.url" value="jdbc:derby:memory:testdb;create=true"/>
<property name="javax.persistence.jdbc.user" value="mymodel"/>
<property name="javax.persistence.jdbc.password" value="password"/>
<property name="javax.persistence.jdbc.schema" value="mymodel"/>
</properties>
</persistence-unit>
For the above, I have a src/test/glassfish folder with a domain.xml file in it with the above and I have code that overwrites the production persistence.xml with the test version.
Enjoy