USING JUMPSTART IN GLASSFISH 2.1.1
WARNING Use GlassFish 2.1.1, not 2.1 or 2.0.GlassFish 2.1 is NOT recommended for JumpStart because it fails JumpStart's integration tests. The reason is that when the business layer throws an exception, GlassFish 2.1 returns an EJBException with no reference to the underlying cause. This makes it impossible for JumpStart's BusinessExceptionInterpreter to interpret the cause.
GlassFish 2.0 is not recommended for JumpStart because it has been discontinued and essential documentation is no longer available.
Contents
Prepare GlassFish
Build and deploy JumpStart
Build and deploy and integration test JumpStart
Use JumpStart
How to run integration tests from Eclipse
How to debug the client side
How to debug the server side
Prepare GlassFish
These instructions prepare GlassFish with the following elements:
Web Server | Business Server | Persistence | Database Server | Logger |
---|---|---|---|---|
Tomcat | GlassFish's EJB3 | Hibernate | Derby | Log4j |
(GlassFish's default) | (GlassFish's default) | (Added by us. We could use GlassFish's embedded TopLink except that JumpStart has a small dependency on Hibernate) | (GlassFish's default) | (Added by us) |
- Start by doing a normal working GlassFish 2.1.1 installation:
- To get it, go to GlassFish Downloads, locate GlassFish Server Open Source Edition 2.1.1 and choose the Download link.
- Download the binary build jar for your platform (eg. glassfish-installer-v2.1.1-b31g-windows-ml.jar).
- Move it to a suitable location (eg. /devel/glassfish-2.1.1/), then follow the instructions they gave to unbundle GlassFish.
- Again go to GlassFish Downloads, locate GlassFish Server Open Source Edition 2.1.1 and choose the Quick Start Guide link.
- Follow the Getting Started instructions until the Admin Console is running (http://localhost:4848).
- Log in (admin, adminadmin).
- Log out.
- Stop it from the command line with asadmin stop-domain domain1 .
- Open the GlassFish config/asenv.conf file and modify the property AS_JAVA to use Java 1.6.
- asadmin start-domain domain1
- asadmin start-database
- Go to the Admin Console web page, eg. http://localhost:4848/. Log in as admin.
- From business/src/test/lib-test/ copy log4j-n.n.n.jar to the server's lib, eg. domains/domain1/lib/.
- From business/src/main/resources/conf-log4j-server-side/ copy log4j.properties to the server's config, eg. domains/domain1/config/.
- In the Admin Console, choose Application Server > JVM Settings > Path Settings.
- Add the paths of the log4j jar and the config directory to the System Classpath, eg.
/devel/glassfish/domains/domain1/lib/log4j-n.n.n.jar
/devel/glassfish/domains/domain1/config
Make sure you replace the n.n.n with the real values.
- In Eclipse, open the project's data_util.properties file and modify the property add.hibernate.to.dir eg. to ../glassfish/lib
- Drag data_util.xml to the Ant view and run its target add-hibernate-to-a-server.
- Check glassfish's lib (eg. /devel/glassfish/lib/) now has the Hibernate jars, (eg. hibernate-core-3.3.2.GA.jar).
- In the Admin Console, choose Resources > JDBC > JDBC Resources
- Add new resource with JNDI Name jdbc/JumpStartDS and Pool Name Derby Pool.
The JNDI Name of this resource is crucial - it is referred to by name in JumpStart's persistence.xml as the jta-data-source. Incidentally, the build will source persistence.xml from business/src/main/resources/persistence-descriptor/glassfish-hibernate-derby-persistence.xml.
- In the Admin Console, choose Application Server > JVM Settings > JVM Options.
- Add JVM options. Here are some to consider:
-Dhibernate.hbm2ddl.auto=update ESSENTIAL for JumpStart initially. Great during development, but
NOT RECOMMENDED IN A PRODUCTION ENVIRONMENT because data can be lost. Tells Hibernate to automatically bring the database structure into line with the app's entity definitions at every restart. See hibernate optional configuration properties.-D64 Indicates you're running Java 1.6 in 64-bit mode (eg. in OS X on an Intel Core 2 Duo). -Dtapestry.production-mode=false Tells the Tapestry ExceptionReport page to display full details of the exception, which is great during development. When set to true (which is the default since T5.0.10), Tapestry's ExceptionReport page will display an abbreviated report so as to avoid disclosing details of your application's internals. See Configuring Tapestry. -Dtapestry.compress-whitespace=false Tells Tapestry not to compress whitespace as it generates a page from a template. Makes the generated page source much easier to read eg. when you tell your browser to display the page source. See Configuring Tapestry.
- asadmin stop-domain domain1
- asadmin start-domain domain1
- deployment.server.type
- deployment.persistence.descriptor
- deployment.web.descriptor
- deployment.server.dir
Build and deploy JumpStart
Here we use Ant to clean, compile, unit test, package, deploy to the server, and wait for it to load.
The deployed package is jumpstart.ear.
- In Eclipse, drag build.xml to the Ant view and run its target clean-compile-test-package-deploytoserver-checkactive.
- If you get an error about JAVA_HOME, read this. Use a JDK 1.6 tools.jar.
Build and deploy and integration test JumpStart
Here we use Ant to clean, compile, unit test, package, deploy to the server, wait for it to load, and run the business integration test suite.
The deployed package is jumpstart.ear. The tests remotely call the JumpStart business layer services exposed by the server.
- In Eclipse, drag build.xml to the Ant view and run its target clean-compile-test-package-deploytoserver-integrationtest.
- If you get an error about JAVA_HOME, read this. Use a JDK 1.6 tools.jar.
Use JumpStart
Ensure the command line is using Java 1.6: the commands java -version and javac -version must return a variant of 1.6, eg. 1.6.0_13.
If GlassFish is not running, start it (as above).
Before you use JumpStart for the first time in a new server, you need to build it, deploy it, and run an integration test.
Then, while the database (Derby) is running, populate it:
- Using your preferred SQL client, replace the data in the database by running the SQL found in business/src/dev/data/initial_data.sql .
How to run integration tests from Eclipse
First, build and deploy JumpStart as described above.
Second, create a User Library over GlassFish:
- In Eclipse, choose Window > Preferences > Java > Build Path > User Libraries (or in OS X, choose Eclipse > Preferences > Java > Build Path > User Libraries), and
- Create a new user library called glassfish-2.1.1-client-lib, then
- Add these JARs from GlassFish's lib/ to the new user library:
- appserv-deployment-client.jar
- appserv-ext.jar
- appserv-rt.jar
- Add this JAR from GlassFish's javadb/lib/ to the new user library:
- derbyclient.jar
|
|
|
- Click Run.
- Watch the results in the JUnit View panel. In the Console View you might see lots of exceptions but that's normal. The JUnit View will tell you quickly whether the tests succeeded or not.
- Problems? Eclipse might not be ready for junit - see Could not create task or type of type: junit.
How to debug the client side
To debug, for example, the client side of the integration tests, use Run > Debug Configurations... instead of Run > Run Configurations....
Eclipse will then stop at breakpoints, display variables, enable single-stepping, etc. in the test suite.
How to debug the server side
To debug any part of JumpStart as it runs in the server you'll need to be running GlassFish in debug mode. There are a couple of ways to do it:
- Start GlassFish in debug mode
We'll use port 8787 in this explanation, but it's OK to use any free port.
Earlier, we described setting various JVM options. To run GlassFish in debug, include these JVM options:
-
-Xdebug -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=y
-
Listening for transport dt_socket at address: 8787
In Eclipse, right-click on your project and choose Debug As > Debug Configurations... and the Debug Configurations window will appear.
- Right-click on Remote Java Application and choose New.
- Set the Port to 8787.
- Enable Allow termination of remote VM.
- Click on Debug.
GlassFish resumes startup, and Eclipse will now stop at breakpoints, display variables, do single-stepping, etc. on any Java in the project.
- Control GlassFish server from Eclipse
There's a GlassFish plug-in for Eclipse but I haven't tried it: http://www.brasee.com/displayPost.htm?postId=42