Posted by bleonard
on May 23, 2006 at 7:54 AM PDT
I hope Geertjan doesn't mind, but I've written Part 3 of his popular blog entry: The Best Feature of the Upcoming NetBeans IDE 5.5.
Last month, my colleague Geertjan wrote a couple of pretty popular blog entries:The Best Feature of the Upcoming NetBeans IDE 5.5 (Part 1 ) and (Part 2 ). It basically showcases 2 new wizards in NetBeans 5.5: Entity Classes from Database and JSF Pages from Entity Class, that when run back to back essentially create a fully functional CRUD (Create, Read, Update, Delete) application. I was curious how this would work with JBoss, so below for you I document my experiences.
- Download and install the NetBeans 5.5 Beta.
- Download and install JBoss 4.0.4. 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 from the Server drop down list. Change the name to JBoss Application Server 4.0.4.
- 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: Create the Project
JBoss doesn't ship any sample data with it's HSQLDB. However, there are a few system tables in place to support JMS, so to keep things as simple as possible, we'll go with one of those: JMS_USERS.
- Create a New Web Application Project named JMSUserEditor. Be sure to select JBoss as the Server (Note, although JBoss supports components of the Java EE 5 specification, notably EJB 3.0, JBoss 4.0.4 is a J2EE 1.4 compliant application server. Therefore, Java EE 5 is not an available option for J2EE Version.). Also, uncheck the option to Set Source Level to 1.4, as we will be using annotations which require Java 5.0.
- On Step 3 of the wizard, Frameworks, be sure to select Java Server Faces and click Finish.
Step 3: Prepare the Project for JBoss
There are a couple of additional steps we need to take in order for the project to run successfully on JBoss. Issues have been filed and these steps will not be necessary with the 5.5 final release.
- Remove the JSF and JSTL libraries from the project (Issue 76733 ). Open the Project Properties, select the Libraries node and Remove the JSF and JSTL libraries from the project.
- Add the MyFaces Context Listener to web.xml (Issue 74392 ). Open the web.xml and expand the Web Application Listeners node. Click Add and add the org.apache.myfaces.webapp.StartupServletContextListener class.
- Press F6 to test run the project. If you can load the page that says Java Server Faces, your project is set up correctly:
Step 4: Setup the Database
Follow the steps from this blog entry to set up HSQLDB to run in server mode. This will allow the wizards in the next step to connect to the database. It will also allow you to use NetBeans' database explorer tools to browse the data.
Step 5: Create the Persistence Unit
- Press Ctrl+N to create a new file and select the Persistence Category > Persistence Unit.
- Set the Persistence Unit Name to default and click Finish.
- Press Alt+Shift+Right to open the XML view and replace the persistence unit with the following:
<property name="hibernate.hbm2ddl.auto" value=""/>
<property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider"/>
Step 6: Create the Entity Classes
- Press Ctrl+N to create a new file and select the Persistence Category > Entity Class from Database File Type.
- Select the Database Connection jdbc:hsqldb:hsql://localhost:1701 [sa on PUBLIC] and the JMS_USERS table.
- Set the Package to entity and click Finish.
Step 7: Create the JSF Pages
- Press Ctrl+N to create a new file and select the Persistence Category > JSF Pages from Entity Class File Type.
- Add the JmsUsers Entity Class to the Selected Entity Classes. Click Next.
- Set the Package to controller and click Finish.
Step 8: Run Your Application
- Press F6 to run the application.