USING JUMPSTART IN JBOSS 7.1.1
These notes apply to JBoss 7.1.1. They were tested with JumpStart 6.9.0.
ContentsPrepare JBoss
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 JBoss
These instructions prepare JBoss with the following elements:
Web Server | Business Server | Persistence | Database Server | Logger |
---|---|---|---|---|
Tomcat | JBoss's EJB3 | Hibernate | H2 | Log4j |
(JBoss's default) | (JBoss's default) | (JBoss's default) | (JBoss's default) | (JBoss's default) |
- Start by doing a normal working JBoss 7.1.1 installation...
- To get it, go to JBoss Application Server Downloads, locate 7.1.1.Final and choose the Download link which will download jboss-as-7.1.1.Final.zip.
- Once downloaded, unzip it. Move it to a suitable location, eg. /devel/jboss-as-7.1.1.Final.
- Add a management user, eg.:
...in Windows:- cd /devel/jboss-as-7.1.1.Final/bin
- add-user.bat
- Answer the prompts to add a Management User in the ManagementRealm.
- cd /devel/jboss-as-7.1.1.Final/bin
- ./add-user.sh
- Answer the prompts to add a Management User in the ManagementRealm.
- Start JBoss, eg.
...in Windows:- cd /devel/jboss-as-7.1.1.Final/bin
- standalone.bat
- cd /devel/jboss-as-7.1.1.Final/bin
- ./standalone.sh
- Log in as the management user:
- Go to the JBoss welcome page, eg. http://localhost:8080/.
- Choose Administration Console and log in as the management user you added above.
- Add the data source JumpStartDS:
- In the Administration Console, choose Profile > Connector > Datasources
- Add new datasource with:
- Name: JumpStartDS
- JNDI Name: java:jboss/datasources/JumpStartDS
- Driver: h2
- Connection URL: jdbc:h2:/devel/jboss-as-7.1.1.Final/standalone/data/jumpstart (adjust this to suit your environment)
- Transaction Isolation: TRANSACTION_READ_COMMITTED
- Username: sa
- Password: sa.
- Enable JumpStartDS.
- Make JBoss's H2 Database module available to all deployments:
- In the Administration Console, choose Profile > Container > EE
- Add new global module with:
- Name: com.h2database.h2
- Stop JBoss.
- Use Ctrl-c back on the command line where you started JBoss.
- Set VM arguments:
- Here are some VM arguments to consider. They are explained further here:
tapestry,
uploading files,
hibernate,
JVM technology
and JVM options.
-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. -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. -Dtapestry.application-version=xxxx RECOMMENDED FOR A PRODUCTION ENVIRONMENT. It is explained here. -Dtapestry.hmac-passphrase=xxxx ESSENTIAL FOR A PRODUCTION ENVIRONMENT. It is explained here. -Dupload.filesize-max=8000000 ESSENTIAL for JumpStart. Tells Apache Commons Upload to limit the size, in bytes, of upload files. -Djumpstart.upload-path=/tmp ESSENTIAL for JumpStart. Tells JumpStart where to save uploaded files. -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.
A better value for production isvalidate
.-server Chooses the "server" JVM (which is optimised for speed). -Xmx512m Gives the JVM more heap memory (to avoid "out of memory" errors). 300m may be sufficient unless you do hot deploys. -XX:MaxPermSize=192m Gives the JVM more Perm Gen memory. If you encounter Perm Gen memory errors then consider this or an even higher setting. 120m may be sufficient unless you do hot deploys. -XX:ReservedCodeCacheSize=24m Gives the JVM a smaller code cache than is the default (we don't need it). -Djava.net.preferIPv4Stack=true Might speed up JBoss startup on some Unixes (clustered AIX?) or other operating systems that have IPv6 enabled by default. - You can set them from the command line:
...eg. in Windows:- set JAVA_OPTS=-Dtapestry.production-mode=false -Dtapestry.compress-whitespace=false -Dupload.filesize-max=8000000 -Djumpstart.upload-path=/tmp -Dhibernate.hbm2ddl.auto=update -server -Xmx512m -XX:MaxPermSize=192m -XX:ReservedCodeCacheSize=24m
- export JAVA_OPTS="-Dtapestry.production-mode=false -Dtapestry.compress-whitespace=false -Dupload.filesize-max=8000000 -Djumpstart.upload-path=/tmp -Dhibernate.hbm2ddl.auto=update -server -Xmx512m -XX:MaxPermSize=192m -XX:ReservedCodeCacheSize=24m -Djava.net.preferIPv4Stack=true"
- Or you can modify JBoss's domain.xml, host.xml or standalone.xml:
- See System Properties in General Configuration Concepts.
- Here are some VM arguments to consider. They are explained further here:
tapestry,
uploading files,
hibernate,
JVM technology
and JVM options.
- Start JBoss, eg.
...in Windows:- cd /devel/jboss-as-7.1.1.Final/bin
- standalone.bat
- cd /devel/jboss-as-7.1.1.Final/bin
- ./standalone.sh
- When you start JBoss you might wish to enable remote access to the web site from other computers:
- Remote access is turned off by default. JBoss does this by binding all its services to localhost (127.0.0.1). A quick way to enable remote access is to bind JBoss to all available network interfaces (0.0.0.0).
- To enable remote access, when you start JBoss you specify -Djboss.bind.address=0.0.0.0 as a parameter, eg.
standalone.bat -Djboss.bind.address=0.0.0.0
./standalone.sh -Djboss.bind.address=0.0.0.0
You cannot specify this in JAVA_OPTS - it won't work.
- Enhance Tapestry's classpath resolver: in the JumpStart project's web/src/main/java/jumpstart/web/services/AppModule.java file, ensure the ClasspathURLConverterJBoss7 line is active (ie. not commented out), like this:
configuration.add(ClasspathURLConverter.class, new ClasspathURLConverterJBoss7());
- Set the build properties: in the JumpStart project's build.properties file, edit the value of these properties:
- deployment.server.type
- deployment.persistence.descriptor
- deployment.server.dir
- Review jboss-hibernate-h2-persistence.xml.
- Hibernate 4 has new strategies for generating entity IDs. By default Hibernate disables them but JBoss AS7 enables them!
You can disable them again by adding the following to business/src/main/resources/persistence-descriptor/jboss-hibernate-h2-persistence.xml:
<property name="hibernate.id.new_generator_mappings" value="false"/>
For more information see https://community.jboss.org/thread/170623 .
- Hibernate 4 has new strategies for generating entity IDs. By default Hibernate disables them but JBoss AS7 enables them!
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 7 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 7 tools.jar.
Use JumpStart
Ensure the command line is using Java 7: the commands java -version and javac -version must return a variant of 1.7, eg. 1.7.0_21.
If JBoss is running, stop it (Ctrl-C).
Before you use JumpStart for the first time in a new server, you need to build it, deploy it, and run the integration tests.
Populate the H2 Database within JBoss with data. H2 provides a handy console to edit the database:
- Find the h2-*.jar in your JBoss server's modules/com/h2database/h2/main/ directory.
- The h2-*.jar is an executable jar file. Double click on it. It will start an application, org.h2.tools.Console, which will then open a web page with the H2 web console.
- Set the JDBC URL, using the full path to your data file, eg. jdbc:h2:/devel/jboss-as-7.1.1.Final/standalone/data/jumpstart.
- Set the User Name and Password to the values you chose above when setting up data source JumpStartDS.
- Click Test Connection. If that fails, correct the settings and try again.
- You will be prompted to enter an SQL statement.
- Replace the data in the database by copying and pasting in the SQL statements found in business/src/dev/data/initial_data.sql, and clicking Run (Ctrl + Enter).
- Close the web page.
- Quit the org.h2.tools.Console application. This releases its lock on the database file.
How to run integration tests from Eclipse
First, build and deploy JumpStart as described above.
Second, create a User Library over JBoss:
- 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 jboss-as-7.1.1-client-lib, then
- Add these JBoss server jars to the new user library:
- bin/client/jboss-client.jar
- modules/org/hibernate/main/hibernate-commons-annotations-4.*.jar
- modules/org/hibernate/main/hibernate-core-4.*.jar
- modules/org/hibernate/main/hibernate-entitymanager-4.*.jar
- modules/org/javassist/main/javassist-3.*.jar
- modules/org/jboss/logging/main/jboss-logging-3.*.jar
- modules/com/h2database/h2/main/h2-*.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 JBoss in debug mode. There are a couple of ways to do it:
- Start JBoss 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 JBoss 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.
JBoss resumes startup, and Eclipse will now stop at breakpoints, display variables, do single-stepping, etc. on any Java in the project.
- Control JBoss server from Eclipse WARNING This section has not been tested since JBoss 6.1.
In Eclipse's Server view, add your JBoss server.
You can set the JVM options, as described above, by right-clicking on the server entry and choosing Open > Open launch configuration > Arguments.
You can start the server by right-clicking on the server entry and choosing Start or Debug.