Create a Blog with JBoss Seam, Hibernate JPA and JSF then Deploy it to Tomcat in the Cloud – Part II

JBoss Seam - Tomcat

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.

Changing perspective in Eclipse

Figure 2.1 - Changing perspective in Eclipse

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.

Switching to the Seam perspective in Eclipse

Figure 2.2 - Switching to the Seam perspective in Eclipse

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.

Defining a new server in Eclipse

Figure 2.3 - Defining a new server in Eclipse

Then in the window which opens, specify the server as Apache Tomcat 6 as shown in figure 2.4.

Adding Tomcat 6 as the web server in Eclipse workspace

Figure 2.4 - Adding Tomcat 6 as the web server in Eclipse workspace

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)

Creating a new Seam web project in Eclipse

Figure 2.5 - Creating a new Seam web project in Eclipse

Now we need to specify the settings and configuration for our new Seam web project which is a blog (CMS).

Specifying configuration of a new Seam web project in Eclipse

Figure 2.6 - Specifying configuration of a new Seam web project in Eclipse

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:

Specifying JSF implementation library for the Seam project

Figure 2.7 - Specifying JSF implementation library for the Seam project

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.

eclipse-new-seam-web-proj-blog3-new-user-lib

Figure 2.8 - Adding JSF libraries to the Seam project manually

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.

Adding JSF 1.2  jar files to user-defined library in Eclipse

Figure 2.9 - Adding JSF 1.2 jar files to user-defined library in Eclipse

Refer to figure 2.9 for a complete list of JSF jar files to our custom library and namely they are:

  • jsf-api.jar
  • jsf-facelets.jar
  • jsf-impl.jar
  • jsf-tlds.jar
  • jstl.jar

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).

JSF settings of Seam web project in Eclipse

Figure 2.10 - JSF settings of Seam web project in Eclipse

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.

Configuring Seam facet

Figure 2.11 - Configuring Seam facet in Eclipse

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.

Specifying Seam 2.2.2 final as the Seam runtime

Figure 2.12 - Specifying Seam 2.2.2 final as the Seam runtime

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.

Configuring database connection profile in Seam

Figure 2.13 - Configuring database connection profile in Seam

Figure 2.14 demonstrates how to configure the database settings in detail:

Configuring MySQL connection profile for Seam project (1)

Figure 2.14 - Configuring MySQL connection profile for Seam project (1)

Configuring MySQL driver for Seam project in connection profile

Figure 2.15 - Configuring MySQL connection profile for Seam project (1)

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.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Selecting MySQL JDBC Driver 5.1

Figure 2.16 - Selecting MySQL JDBC Driver 5.1 for Seam project

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.

Editing the JAR location

Figure 2.17 - Editing the JAR location

 

 

 

 

 

 

Indicating the file path of MySQL JDBC driver library (jar)

Figure 2.18 - Indicating the file path of MySQL JDBC driver library (jar)

Database Connection details

Figure 2.19 - Seam database connection details

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.

Finalize Seam web project creation

Figure 2.20 - Finalizing Seam web project creation

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.

Be Sociable, Share!

Leave a Reply

Your email address will not be published. Required fields are marked *


*