JSF Article

This site is used to support the JSF article that Rick Hightower wrote for IBM developerWorks.

You can find resources for the article at this site.

The source code is provided at this site as well.

The source code comes with an ant build script, a maven build script, and Eclipse project files. I used MyEclipse to test/debug the project. I used Maven to build it.

Since the project relies on jar files from Sun, the distribution is a bit difficult.

If you are using Maven, you will have to copy the jar files for JSTL and JSF to your local maven repo. A list of jar files that this project uses is in the project.xml file under the tag dependencies.

The ant build file was generated from Maven. Maven can generate ant build files. I modified the file to build a war file. I tested the war file with Tomcat 5, and it works. The ant build file is simplistic and small.

The source directory also has a .classpath and a .project so you can open this project in Eclipse. If you are using MyEclipse, it will find its project files and work as expected.

 

You can find the source code with no jars here.

You can find the source code with some jar here.

Maven generated site (note the site is really light as this is just an example JSF project).

JavaDocs for class.

Java code in HTML for classes.

 

This page is not finished. It is a place holder.

Here are some instructions on how to get started with Maven. This work is based on work that Warner Onstine was paid to do for ArcMind. These are instruction are copied from a Word Document into Dreamweaver. The orginal looks nicer, but this is free. Also some parts were edited as they did not make sense in this context.

Getting Started with Maven:

Familiarize yourself with Maven

Objective: We are going to familiarize ourselves with Maven. Maven was originally created to remove a lot of the redundancy that was found using Ant. Copying tasks from one project to another or having to install new jars to take advantage of custom Ant tasks can be tedious and error-prone, especially if you copy from an old project and have now found a better way to do things.

What is Maven?

 

Originally Maven was based on Ant, but has since moved past that and is now a complete standalone build system that uses what we call “plugins” to manage custom builds. By utilizing “plugins” Maven makes it easier to take advantage of a new way of performing a task, or creating a new task.

 

Installation Overview

 

Installing Maven is relatively straightforward; it’s simply a matter of either installing the Windows executable or manually unpacking the binary distribution into your chosen location. (Our assumption is that if you are installing this on a Mac, Linux or Unix that you can translate these instructions to your platform, since you likely have a lot of practice. Frankly, more is expected of you.)

 

See Maven install and download pages to download zip file or Windows installer .

Unzip zip file or run installer.

We will outline the general process needed to install Maven, then we will give a step by step example.

Before you begin using Maven you will need to define the MAVEN_HOME environment variable, which is the directory where you unzipped Maven. (If you are using the Windows Installer this variable will be set for you). You will also need to add MAVEN_HOME/bin to your path so that you can run the scripts provided with Maven. This works in exactly the same way that Ant works.

You will also need to define the JAVA_HOME environment variable. This variable should be the directory where a Java Development Kit is installed, i.e. the directory that contains the bin, demo, jre and lib directories

In the top-level directory of MAVEN_HOME , you should see the following structure:

Text Box:       .       |-- bin       |-- lib       |-- plugins

If the above directory structure is present you have everything you need build projects with Maven.

 

Text Box: maven -v

To confirm that you can start Maven, type the following command in a DOS box.

Here is a step-by-step example;

ACTION: Maven should have been installed in “c:\arc-mind\maven”. You will need to set an environment variable called MAVEN_HOME to “C:\arc-mind\maven”.

 

In Windows XP you would do the following steps

  1. Select [START] button at bottom of computer screen
  2. Select [Control Panel] icon
  3. Select [Performance & Maintenance]
  4. Select [System]
  5. Select [Advanced] tab
  6. Select [Environment Variables] button
  7. Select [New] variable


  8. Enter variable name and value as shown below


ACTION: You will also need to add Maven to your PATH environment variable as well. To do so add the following to your PATH: %MAVEN_HOME%\bin


In Windows XP you would do the following steps



 


You have successfully completed this task!

Ensure that Maven is installed
and working properly

Objective: In this task, you will test the installation you did in the last step. If all goes well we will be ready to start having some real fun!

 

Action: The simplest way to test that Maven is working is to type:

maven --version

Text Box: maven -v   __  __  |  \/  |__ _Apache__ ___  | |\/| / _` \ V / -_) ' \  ~ intelligent projects ~  |_|  |_\__,_|\_/\___|_||_|  v. 1.0-rc3

at the command-prompt.

Fig - (2)

 

This will attempt to find the Maven program and run the “version” command. What you get back should look something like fig-2.


This tells us that we have Maven 1.0 release candidate 3 installed and running. You may additionally see some other information go by as Maven installs updated plugins for you.

ACTION: Test Maven out on our project;

1. Open DOS box


2. Change directory to the jsf-simple directory by entering:
CD C:\arc-mind\jsf-quickstart\labs\jsf-simple
then press enter


3. Now type:
maven java:compile
and press enter

 

This will attempt to compile our code, since there isn’t much there yet nothing, Maven should build the project successfully. Now let’s finish up the configuration of our JSF application.

 

ALTERNATE ACTION:
If you are using MyEclipse or other Eclipse plugins that run the AppServer in the Eclipse IDE, then you may want to copy the jar files to webapp/WEB-INF. We provided a Maven goal named getWebJars.



Text Box: maven getWebJarsFig - (3)

The goal getWebJars copies the jar files from the Maven repo to the webapp/WEB-INF directory. We highly recommend using MyEclipse set of plugins for JSP code completion, JavaScript highlighting, web app deployment, and more. (If not MyEclipse than another tool that provides the same. IBM WSAD is a good choice.)

 

You have successfully completed this task!

 

The main goal you want to run for the JSF article is war. The war goal is the default goal. Goals are like targets in ant.

If you are using Maven, you will have to copy the JSF jar files into your local repo. You local repo is in your user directory.

E.g., on my machine, the maven local repo is located at C:\Documents and Settings\RickHigh\.maven\repository.