This tutorial demonstrates a method for creating a .war file including JSF pages
in JDeveloper 11g. This is also available at: http://tmoodini.com/tutorials/jdevtomcatjsf.htm.
There are a few ways to deploy web applications to Tomcat from JDeveloper 11g.
If your Tomcat installation resides on a separate machine from your JDeveloper installation,
one method is to create a .war file and deploy it through the Tomcat manager.
A big advantage of this method is that it bundles all of the necessary .jars for
things like JSF pages in your .war file if properly included in the Libraries of
your project, not to mention portability.
Go to File ->New->Applications->Java EE Web Application
Follow the wizard and set it up to your liking. On step 2 of the wizard be
sure that HTML, Java, JSF, JSP and Servlets
are in the "Selected" box of the Project Technologies tab:
In the project explorer on the left right click on the Web Content folder and choose
"New".
In the menu that appears select JSF and JSF Page:
Name the new file helloworld.jsp and click ok:
Open the code for helloworld.jsp and put the following between the body tags:
<h:outputtext value="Hello JSF World!">
Now we will make sure the correct libraries are imported.
Go to Tools->Project Properites->Libraries and Classpath and click "Add JAR/Directory".
Add the following .jars:
- jsf-api.jar (By default in the 11g installation it is in the jdeveloper\jsf-ri folder)
- jsf-impl.jar (By default in the 11g installation it is in the jdeveloper\jsf-ri
folder) - jstl.jar (By default in the 11g installation it is in the jdeveloper\modules\jakarta.jstl_1.1\lib
folder) - standard.jar (By default in the 11g installation it is in the jdeveloper\modules\jakarta.jstl_1.1\lib
folder) - org.apache.commons.beanutils_1.6.jar (By default in the 11g installation it is in
the jdeveloper\modules folder) - org.apache.commons.collections_3.1.jar (By default in the 11g installation it is
in the jdeveloper\modules folder) - org.apache.commons.digester_1.7.jar (By default in the 11g installation it is in
the jdeveloper\modules folder) - org.apache.commons.logging_1.0.4.jar (By default in the 11g installation it is in
the jdeveloper\modules folder)
Now we need to create a deployment profile.
From the menu select Build->Deploy->New Deployment Profile. In the menu
select WAR File.
Name the file testjsf and click "OK".
On the next screen use the default settings and click OK.
On project properties be sure to check under Compiler to make sure your version
compatibility (e.g. 1.5 or 1.6) is set appropriately for your Tomcat deployment.
Now we need to make a slight change to our web.xml file.
Click the web.xml file in the explorer and then open its source. You can do
this through the interface provided by JDeveloper if you prefer.
Change the section that looks like this:
<servlet-mapping>
<servlet-name>
Faces Servlet
</servlet-name>
<url-pattern>/faces/* </url-pattern>
</servlet-mapping>
To this:
</servlet-mapping>
</servlet-name> Faces Servlet </servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
Now right click on your project folder and select "Deploy".
Select your deployment profile (should be testjsf in this case) and "to WAR" file.
We are ready to upload to Tomcat.
Log into your Tomcat Manager application and under WAR File to Deploy click browse
and select the newly created testjsf.war and then click deploy.
Once deployment is finished you should be able to view your page at http://<yourtomcatinfo>/testjsf/helloworld.jsf.
No comments:
Post a Comment