 |
Elvis, Meet Portability
Posted by bleonard on April 14, 2006 at 12:59 PM | Comments (5)
Last month I took a Cay S. Hortsmann article, Elvis Meets GlassFish, and demonstrated how you could use the NetBeans 5.5 Preview to make Elvis even happier. I was curious what it would take to make that same application run on JBoss. Elvis continues to smile.
Getting Started
- Download and install the NetBeans 5.5 Preview. This will install both NetBeans and if needed, the GlassFish Application Server.
- Build the Quiz application as documented in my previous entry, Elvis, Meet NetBeans.
- Download and install JBoss 4.0.4 (CR2 at the time of the blog entry). During installation, be sure to select the ejb3 profile.
Step 1: Add the JBoss Server to NetBeans
- Switch to the Runtime tab and right-click the Servers node to add a server.
- Select JBoss Application Server 4.0.3 from the Server drop down list. Change the name to JBoss Application Server 4.0.4 CR2:
- Complete the Add Server wizard.
- Stop the Sun Java System Application Server if it is running (both servers use http port 8080 as their default).
- Right-click the new JBoss server node and choose Start:
Step 2: Update and Deploy the Quiz Application to JBoss
We need to make a couple of changes to the Quiz application in order for it to successfully deploy to JBoss.
- If not already open, open the Quiz project
- Open the Quiz project properties, select the Run category, and change the Server from Sun Java System Application Server to JBoss Application Server 4.0.4 CR2:
- Delete the ejb-jar.xml Configuration File from the Quiz-EJBModule. The JBoss Server does not yet recognize all of the namespaces declared in this file which will cause deployment to fail. Also, because we're using EJB3 annotations, this file is now empty and no longer necessary:
- Open persistence.xml and replace the persistence-unit element with the following in order to use the embedded HSQL database in JBoss:
<persistence-unit name="default"> <jta-data-source>java:/DefaultDS</jta-data-source> <properties> <property name="hibernate.hbm2ddl.auto" value="create-drop"/> </properties> </persistence-unit>
- Right-click the Quiz project and choose Clean & Build Project. This is necessary in order to remove the ejb-jar.xml from the previously build.
- Right-click the Quiz project and select Deploy Project
Step 3: Update the Client
Actually, our client is so simple that it's easier to just re-create it.
- Create a new General Java Application project, JBossQuizClient. Set the Main Class to elvis.client.Client.
- QuizClient needs access to several libraries:
- The JBoss Client Libraries. Right-click the Libraries node and choose Add Jar/Folder. Browse to your <JBoss installation directory>/client folder and select the following jars:
- jbossall-client.jar
- jboss-ejb3-client.jar
- jboss-aop-jdk50-client.jar
- jboss-aspect-jdk50-client.jar..
- The Quiz session interface. Right-click the Libraries node and choose Add Jar/Folder. Browse to your <Quiz project directory>/Quiz/Quiz-ejb/build directory and select ear-module.
- Add the following to main, including the throws clause:
public static void main(String[] args) throws Exception { Hashtable env = new Hashtable(); env.put("java.naming.factory.initial",
"org.jnp.interfaces.NamingContextFactory"); env.put("java.naming.provider.url",
"jnp://localhost:1099"); env.put("java.naming.factory.url.pkgs",
"org.jboss.naming:org.jnp.interfaces"); InitialContext ctx = new InitialContext(env);
TestRemote test = (TestRemote) ctx.lookup("quiz/TestBean/remote"); long id = test.makeQuiz(); System.out.println(test.getQuiz(id)); }
- Press Alt+Shift+F to fix the imports.
- Press F6 to run the JBossQuizClient. You should see the following in the Output window:
Step 5: Spying on the Database
By default, the HSQL database runs in embedded (in-process) mode. In order to use NetBeans' database explorer tools, we need to switch the database to server mode.
- Outside of NetBeans, browse to your <JBoss installation directory>/server/default/deploy directory and open the HSQL configuration file, hsqldb-ds.xml.
- Uncomment the connection-url element to used for server mode:
And comment the connection-url used for in-process persistent db mode.
- Comment the depends element used for in-process mode and uncomment the depends element used for server mode:

- Uncomment the mbean element used for server mode and comment the mbean element used for in-process mode:
- Switch to the NetBeans Runtime tab and restart JBoss.
- While still in the Runtime tab, expand the Databases node and right-click the Drivers node and choose Add Driver:
- In the Add JDBC Driver dialog, click Add and browse to your <JBoss installation directory>/server/default/lib directory and select hsqldb.jar. NetBeans will locate the driver class, org.hsqldb.jdbcDriver and suggest a name, HSQLDB. Click OK:
- Right-click the new HSQLDB driver node and select Connect Using:
- Set the Database URL to jdbc:hsqldb:hsql://localhost:1701 and the User Name to sa. Leave Password blank:

- Click OK and select the PUBLIC schema when prompted.
- Expand the hsqldb connection > Tables node. Right-click the QUESTION table and select View Data.
Bookmark blog post: del.icio.us Digg DZone Furl Reddit
Comments
Comments are listed in date ascending order (oldest first) | Post Comment
-
Cool. Thanks for that. I learned something new ;-). Oh and btw. after changing to the HSQLDB server setup you need to run the JBossTestClient again if you want to see any data in the server database. At least that did the trick for me.
Posted by: mosabua on April 19, 2006 at 02:10 PM
-
Oh and before I forget. I look forward to the web interface (JSF i suppose) follow up.
Posted by: mosabua on April 19, 2006 at 02:11 PM
-
I tried this with Netbeans 5.5beta but I did not have the JBoss Application Server 4.0.3 to choose. Instead there is only the JBoss Application Server 4 option, which did not support JEE5. Could it be, that this works only with Netbeans 6 (where i have the JBoss 4.0.3 option)? Are those available servers configurable anywhere?
Posted by: ttretau on July 13, 2006 at 03:21 AM
-
Although the NetBeans 5.5 Beta lists JBoss 4.0.3 in the
Add Server dialog, it will also work with JBoss 4.0.4 (as is shown in the Add Server Instance dialog above). However, JBoss is not a Java EE 5 compliant application server (the JBoss installer states this very clearly). Now, JBoss does support some Java EE 5 features, like EJB 3.0, which is what this blog entry is really about. Does this answer your question?
Posted by: bleonard on July 13, 2006 at 07:44 AM
-
Hi Brian! Sorry, thought that my problem had to do with the version number. Now i figured out that my problem was my JBoss installation.. Thanks for your support and your nice example!
Posted by: ttretau on July 13, 2006 at 12:41 PM
|