Installing the JavaServer Faces Web application framework

Obtain and install the JavaServer Faces Web application framework as a solid basis for deploying Java applications on a Tomcat server.

JavaServer Faces (JSF) is a Java Web application framework. Once you have the core Java development kit (JDK) and an application server to run it on, the third tool you'll need in order to build and deploy Web applications is a Web application framework. JavaServer Faces is a good standard choice for building enterprise applications because it has gone through the Java community process and is officially a part of the Java Platform, Enterprise Edition (Java EE). This video tutorial will guide you step by step through the process of downloading and installing the latest stable version of JavaServer Faces and configuring it to work on your system, including finding and placing important .war files in the proper library directories. For your convenience, a written transcription of the video follows.

Click here to view a larger sized video.

Hi, I’m Cameron McKenzie. I’m the author of “Hibernate Made Easy” “JSF Made Easy,” a few Java certification guides as well. I want to guide you in this tutorial through just the basic configuration and obtaining of a JavaServer Faces [JSF]  implementation. As you can see I’ve actually got the JDK installed and I’ve got Tomcat installed as well. I’ll open up the command prompt and just do something as simple as echo %JAVA_HOME%, you’ll notice I’ve got the JAVA_HOME environment variable setup as well. Of course I can always go to the Tomcat installation directory and issue a startup command. You’ll see that my Tomcat server actually starts up. It starts up pretty darn fast if you look at that.

I’ve got a JDK installed. I’ve got Tomcat installed. What I want, though, is an environment that will actually make it possible to do JSF development because JSF doesn’t come standard with Tomcat installation, a Tomcat 6 installation. In order to start working with JSF I need to actually obtain a JSF implementation. One place to get it is through Javaserverfaces.dev.java.net. It’s essentially the Sun site, or I should say Oracle site. If I go here you’ll actually see there are a number of resources that are available. I want to go to the JSF download. There is JSTL there, that’s important as well. I’ll go to JSF downloads. There are a whole bunch of downloads, 2.0 was released. I’m actually interested in 1.2 right here and I’m interested in downloads for the latest 1.2 version, which is 1.2 update 14.

When I click on that particular link, JSF 1.2_14, it looks like it was just right there at the end of 2009. There is a source file and a binary file. I’m actually going to download the binary file. It’s about eight and a half MB in size. I’ve actually cheated a little bit. If I actually say “show in folder” there is actually the download completed, 8741 KB, that’s not too bad. I’m going to open that particular folder up and using WinZip just extract that to the root of C. Now it doesn’t get splattered into the root of C if I actually go and take a look at my C drive, I’ll notice that—if I do a quick refresh – there will be a little folder in there that is the embodiment of the JSF implementation. I’m just going to rename that. I like renaming everything with a leading underscore. I’ll call that JSF1.2 and when I look in there, there are all sorts of delicious folders. I’ve got my Java docs folder. It’s really worthwhile just going in there and taking a look at that Java docs folder, even bookmarking it so that you’ve now got easy access to the JSF API.

Another couple of interesting and important files in here are these different .war files. You’ll notice there is a guest number, components and jsf-cardemo.war. What I want to do to sort of prove that my JSF implantation is working, is actually deploy this jsf-guessNumber.war file. Now if I actually click on the jsf-guessNumber.war file I can copy it from the samples of the JSF1.2 folder. I can move it into the webapps directory of my Tomcat installation. As I do that, very quickly Tomcat will recognize that something has been placed in there. You’ll actually see it tries to deploy that jsf-guessNumber.war file.

One of the problems here is this particular JSF number guesser, when I go in and look at its lib directory there is nothing there. In order for a JSF application to work properly your JDK and your Tomcat server need to be able to link to a couple of important files at runtime. They need to be able to access the JSF API and the implementation of that API, which is contained in two .jar files. It also will need an implementation of JSTL, the standard tag library. That is found and embodied in the jar files, standard .jar and JSTL.jar. The question is where do we get these .jar files?

One of the places you can get them is actually just going into your JSF download and looking in the lip directory. You’ll notice there is a jar called “jsf-api.jar” and “jsf-impl.jar” I am going to take those two files. I’m going to place them in the lib directory of the JSF number guesser and click paste. Paste them in there, we get them. Then, I’m also going to look for the standard.jar and JSTL.jar files. Where can you find those?  You can actually download them. You can download them from Sun. As you can see there is this JSTL link on the JSTL.dev.java.net website. Another place that I like to get them and this is because I’m lazy and it’s easy to do, if you actually go into Tomcat you will notice there is an examples folder. That’s a set of examples you can look at and use as references. You’ll notice that the JSTL.jar and standard .jar files are in there. I know this is copying, but if you take those two .jar files and you move them into a little number guesser lib folder all of a sudden this application now has the four .jar files that we need in order to run the JSF applications.

Any JSF application needs the implementation of the JSF API. That’s embodied in those two .jar files that I’ve obtained from Sun Microsystems. IBM also has their own set of .jar files and you can get MyFaces implementations as well. Those particular files need a JSTL implementation and these two files are required for JSTL. With all of that placed into this number guesser folder what I am going to do is I’m going to stop my Tomcat server and I’m going to start it up again. It’s just like bouncing the server so that I make sure everything is running. As you see right here we are now trying to run that JSF number guesser application.

I’ve actually set up the link in order to gain access to that application that has been deployed. If I go to http://localhost:8080/jsf-guessNumber/—make sure there is an uppercase “N” there. If you go to that particular link, you’ll get a little bit of information coming up there; get a couple little logs in here. Notice I got a little answer on what the number is. I come here and I’ve got the java mascot and he’s asking me what that number is from one to ten. I actually saw on the log files, it looks like its number is three but I’m going to put in the number “2.” It says I have to try a larger number. I’m going to type in “4.” It says I have to type in a smaller number so I go back here and I try “3” and it says “Yay! you’ve got it!”

So what have I done here? Essentially what I’ve done is I’ve taken my Tomcat server, which is working because I’ve got a JDK installed and the Java home set. I’ve downloaded an implementation from the Java server faces framework from Sun Microsystems at this particular link right here. I have then taken one of their examples and I have deployed it as a .war file; jsf-guessNumber.war to my Tomcat server simply by placing it in the webapps directory. Then I have tested that application. However, before testing it I had to make sure that particular application has the JSF implementation and the JSTL implementation in the lib directory so that at runtime the application can access those particular files.

The other thing I’m going to say is I’m going to copy those files right into the JSF1.2 root directory there because in order to actually run my applications I’m going to need to link to those particular files. Anytime I want to compile programs or run programs that use JSF or JSTL, I need to link to those particular files. Throwing them into that JSF1.2 folder for now is going to make them very easy to locate.  And that’s about it. That’s how easy it to obtain a JSF implementation from Sun and deploy a JSF application to your Tomcat server.  That’s about it for now, happy JSF.

Dig Deeper on Front-end, back-end and middle-tier frameworks

App Architecture
Software Quality
Cloud Computing
Security
SearchAWS
Close