This document discusses how to configure and deploy a Java EE application with Seam and JPA/Hibernate on GlassFish using Ant build scripts. It includes tasks for starting and stopping GlassFish, deploying Hibernate as the JPA provider, configuring datasources and JNDI references, applying property replacements, and achieving hot deployment. The build scripts demonstrate how to integrate Seam components and transactions as well as work around issues with RichFaces on GlassFish.
11. Adding GlassFish targets
Define in separate Ant build file
– glassfish.build.xml
Prefix targets to avoid naming conflict
– prefix: “gf-”
Import into build.xml (before first target)
<import file=quot;${basedir}/glassfish.build.xmlquot;/>
13. Using the asadmin macro
Starting the server
<asadmin cmd=quot;start-domainquot; args=quot;${glassfish.domain}quot;>
<pre-conditions>
<fail unless=quot;glassfish.domainquot;>glassfish.domain not set</fail>
</pre-conditions>
</asadmin>
Stopping the server
<asadmin cmd=quot;stop-domainquot; args=quot;${glassfish.domain}quot;>
<pre-conditions>
<fail unless=quot;glassfish.domainquot;>glassfish.domain not set</fail>
</pre-conditions>
</asadmin>
Registering a data source
<asadmin cmd=quot;add-resourcesquot;
args=quot;${basedir}/resources/glassfish-resources-${profile}.xmlquot;/>
14. <target name=quot;gf-deploy-hibernatequot;
description=quot;Deploys Hibernate to be a JPA provider on GlassFishquot;>
<fail unless=quot;glassfish.homequot;>glassfish.home not set</fail>
<fail unless=quot;glassfish.domainquot;>glassfish.domain not set</fail>
<copy todir=quot;${glassfish.home}/domains/${glassfish.domain}/lib/extquot;>
<fileset dir=quot;${basedir}/libquot;>
<include name=quot;antlr.jarquot;/>
<include name=quot;asm.jarquot;/>
<include name=quot;asm-attrs.jarquot;/>
<include name=quot;cglib.jarquot;/>
<include name=quot;commons-collections.jarquot;/>
<include name=quot;commons-logging.jarquot;/>
<include name=quot;concurrent.jarquot;/>
<include name=quot;dom4j.jarquot;/>
<include name=quot;hibernate.jarquot;/>
<include name=quot;hibernate-*.jarquot;/>
<exclude name=quot;hibernate-search.jarquot;/>
<include name=quot;javassist.jarquot;/>
<include name=quot;jboss-common-core.jarquot;/>
<include name=quot;jta.jarquot;/>
<include name=quot;persistence-api.jarquot;/>
<include name=quot;mysql-connector-java-5.1.6.jarquot;/>
</fileset>
</copy>
</target>
23. /build.xml (war target)
<target name=quot;warquot; ...>
...
<fileset dir=quot;${basedir}/viewquot;>
<include name=quot;**/*.xcssquot;/>
</fileset>
<fileset dir=quot;${basedir}/resourcesquot;> Add fileset to copy the provided theme
<include name=quot;**/*.xcssquot;/>
resource (theme.xcss) to the classpath
</fileset>
... to workaround bug in RichFaces with
</target> GlassFish.
24.
25.
26.
27. Achieving hot deploy
jboss-seam.jar must be exploded since it
contains an EJB
– Deploy exploded EAR from staging area
– gf-explode uses “adadmin deploydir”
Run staging target
– gf-hotdeploy runs “ant stage”
Seam's hot deploy classloader works!
– The catch: only works with a WAR, not an EAR
28. Container-managed persistence
Persistence unit must be deployed in a
separate JAR
JAR must be in EAR lib directory and
cannot be exploded
Requires additional configuration in
components.xml, persistence.xml, and
web.xml
Allows you to use @PersistenceContext
29. Commands to develop by
gf-start - Starts GlassFish
gf-stop - Stops GlassFish
gf-restart - Restarts GlassFish
gf-datasource - Registers the datasource and connection pool for the
profile
gf-explode - Deploys the exploded archive to GlassFish (initial)
gf-hotdeploy - Hot deploys Java classes and components (exploded only)
gf-deploy - Deploys the packaged archive to GlassFish
gf-undeploy - Undeploys the exploded or packaged archive from GlassFish
gf-deploy-hibernate - Deploys Hibernate as a JPA provider to GlassFish