In part I of the tutorial, I provided the instructions about the development environment and how to create the blog’s database. In this part II, using Eclipse’s JBoss tools plugin, we’ll create and configure the JBoss Seam web project and prepare it for full Tomcat-compatibilty and for the creation the basic CRUD (create, read, update and delete) functionality of entities which will be reverse engineered from the database using hbm2java embedded in Seam-gen whose GUI version comes built-in with JBoss Tools.
The Development Environment
To be able to follow the tutorial and reproduce the same results, it’s best (if not mandatory) that you have exactly the same version of the tools and plug-ins I mentioned in the previous post. As of this part (and so on) I’ll instruct on Eclipse Helios with JBoss Tools 3.2. You can also refer to my post titled ‘Matrix of compatible platforms and runtimes with JBoss Tools‘ to see which version of Eclipse and other stuff (such as Seam framework version) is compatible with which version of JBoss tools plugin, etc.
So here we go. Now launch Eclipse if you already haven’t done so.
First of all, we shall change the perspective in Eclipse to Seam – that option, however, is only available if you have JBoss tools installed. See figure 2.1 and 2.2.
Now since we need to define a server runtime – in this case Apache Tomcat, go to the Servers tab on the bottom pane, right click the empty area and select New > Server as shown in figure 2.3.
Then in the window which opens, specify the server as Apache Tomcat 6 as shown in figure 2.4.
As you select Tomcat v6.0 server from the Apache category in the list box, server’s host name will automatically be set to localhost as well as server name field being set to Tomcat v6.0 Server at localhost which are descriptive and good enough, therefore we’ll leave the rest as it is and click next, then finish.
Creating the Seam project for Tomcat and MySQL
Now we’re ready to create our Seam project. From the File menu on Eclipse’s main menu bar select New > Seam Web Project as shown in figure 2.5. (Last reminder: this option only available if you have JBoss Tools installed, otherwise see the beginning of this post)
Now we need to specify the settings and configuration for our new Seam web project which is a blog (CMS).
Referring to figure 2.6, you can make the following settings.
- Project name: blog
- Target runtime: Apache Tomcat 6.0
- Dynamic web module version: 2.5
- Target Server: Tomcat v6.0 server at localhost
- Configuration: Dynamic Web Project with Seam 2.2
Click Next twice and you will get something like in figure 2.7:
In this screen (as shown in figure 2.7), we need to specify the JSF implementation library which is to be Mojarra 1.2. If we had chosen a JBoss Application Server for deployment, we would have had the possibility of using the libraries bundled with the JBoss runtime. Since we’ll deploy to Tomcat we need to go with the user library option which we need to provide ourselves. So click the tiny ‘manage libraries’ button and click ‘New..’ in the new window which opens. Here, I named the new user library as GO-JSF. You can name yours whatever you want as this is a one-time thing.
Now after you provide the name for the new user library intended for our JSF jars, we we need to put them in there. Make sure you have downloaded Mojarra 1.2 jars or my bundle called GO-JSF and have them somewhere accessible and ready (as separate jar files) on your computer.
Refer to figure 2.9 for a complete list of JSF jar files to our custom library and namely they are:
Click OK and then make sure the user JSF library’s checkbox is checked as well as an option saying “include libraries with this application”. The remaining settings regarding JSF in this screen should be as good as defaults, so you can click ‘next’ if what’s on your screen resembles figure 2.10 (otherwise make your settings similar to it).
On the next screen we need to specify the Seam runtime and a database connection profile for ORM. If you’re making a Seam development for the first time with the IDE, the Seam runtime selection pop-up menu will probably be blank in which case we need to add one. We want Seam 2.2.2, so if it is not present as an option we need to ‘add’ it.
After clicking ‘Add’ (assuming you needed to), you should click browse in the pop-up window, to specify the location of the Seam framework folder you have (downloaded) on your hard-drive. Make sure it’s version 2.2(.2) and click Finish.
Finally we can enter the database settings. Select MySQL (InnoDB) for database type and click ‘New’ or ‘Edit’ depending on whether you’re doing this for the first time in the given workspace or not.
Figure 2.14 demonstrates how to configure the database settings in detail:
When you reach to the next screen, you will need to specify the version and location of the MySQL JDBC driver library (.jar) if you’ve never done this before in the current workspace.
You’ll know what to do if the drop-down list is blank or you don’t see an item indicating that MySQL 5.1 JDBC driver is installed. (See figure 2.15) Just click the tiny button next to it on the right and then refer to figure 2.16.
Switch to the Jar List tab in the New Driver Definition window to put in the appropriate MySQL JDBC jar, otherwise the OK button won’t even be active to save the settings and close the window.
After you specify the location of the jars, you can specify the connection details as shown in figure 2.19 and finalize the settings. Also click the Test connection button to see if you have configured everything properly. If the ping fails, repeat the steps to create a connection profile and defining the JDBC driver.
As soon as the connection settings are OK, we will lastly specify the model and the controller package names under the source code generation section. Session bean package name refers to the controller although we won’t use any EJB here since we’re sticking with Tomcat.
Enter net.ozar.blog.session for the controller package name, and net.ozar.blog.entity for the entity bean package name, and then click the Finish button to finalize the creation steps of the Seam web project, in this case the blog.
In part III of the tutorial, we will create the model layer and some basic controller code (for CRUD operations) and then modify the project’s configuration so as to make it Tomcat-compatible.