JSF Examples Set Up

27
1 JSF Example Set up Contents 1 Prerequisite ................................................................................................................................................ 2 Java JDK version 5 or Higher .................................................................................................................. 2 Java EE 6 Speciation .................................................................................................................................. 2 Source Code .............................................................................................................................................. 2 2 Eclipse ........................................................................................................................................................ 3 Download .................................................................................................................................................. 3 Extract ....................................................................................................................................................... 4 3 Tomcat ....................................................................................................................................................... 5 Download .................................................................................................................................................. 5 Extract ....................................................................................................................................................... 6 Configure................................................................................................................................................... 7 Validate ..................................................................................................................................................... 8 4 Maven ..................................................................................................................................................... 10 Download ................................................................................................................................................ 10 Extract ..................................................................................................................................................... 11 M2Eclipse Maven Plug-in for Eclipse ...................................................................................................... 11 5 Building the Web Application using Maven Project ................................................................................ 13 6 Deploying the Web Application using Tomcat Manager App .................................................................. 15 7 Workspace Set up with Eclipse and Tomcat ............................................................................................ 16 7 JSF Code import from WAR File ............................................................................................................... 18 8 Set up workspace from Maven Project .................................................................................................... 21

description

JSF setup and testing

Transcript of JSF Examples Set Up

  • 1

    JSF Example Set up

    Contents 1 Prerequisite ................................................................................................................................................ 2

    Java JDK version 5 or Higher .................................................................................................................. 2

    Java EE 6 Speciation .................................................................................................................................. 2

    Source Code .............................................................................................................................................. 2

    2 Eclipse ........................................................................................................................................................ 3

    Download .................................................................................................................................................. 3

    Extract ....................................................................................................................................................... 4

    3 Tomcat ....................................................................................................................................................... 5

    Download .................................................................................................................................................. 5

    Extract ....................................................................................................................................................... 6

    Configure ................................................................................................................................................... 7

    Validate ..................................................................................................................................................... 8

    4 Maven ..................................................................................................................................................... 10

    Download ................................................................................................................................................ 10

    Extract ..................................................................................................................................................... 11

    M2Eclipse Maven Plug-in for Eclipse ...................................................................................................... 11

    5 Building the Web Application using Maven Project ................................................................................ 13

    6 Deploying the Web Application using Tomcat Manager App .................................................................. 15

    7 Workspace Set up with Eclipse and Tomcat ............................................................................................ 16

    7 JSF Code import from WAR File ............................................................................................................... 18

    8 Set up workspace from Maven Project .................................................................................................... 21

  • 2

    1 Prerequisite

    Java JDK version 5 or Higher

    Java EE 6 Speciation Examples have been built on Java EE Specification i.e.: Servlet Specification 3.0 , JSF 2.0. The examples can be run in Java EE 5 Containers as well, with appropriate updates to the web.xml file.

    Note: The document describes setting up of the JSF example on local workspace, This documents uses the following:

    1) Eclipse IDE 2) Tomcat Version 7 Server 3) Maven Build 4) JSF Sun Reference Implementation (Mojarra Faces Implementation)

    Source Code Source Code for the examples are available if the following formats

    1) Maven Project This can be used to build the maven project and deploy to any Java EE Server. The maven project can also be imported as a maven project, tweak the project facets to be able to run as a Dynamic Web Application within any Java EE IDE with a compliant servlet container.

    2) Exported Project WAR This can be either deployed to any Java EE Server, or be imported into a Java EE complaint IDE and run as a Dynamic Web Application within IDE.

  • 3

    2 Eclipse Following steps explain set up of Eclipse on local workstation. This document uses Eclipse Helios v3.6

    Download Download Eclipse IDE for Java EE Developers from the following URL: http://www.eclipse.org/downloads/

    http://www.eclipse.org/downloads/

  • 4

    Extract Extract the binary zip file to C:\ Drive

    TIP: Add the Following lines to the eclipse.ini file based on available memory on the machine, -Xms756m -Xmx1024m This is not a requirement but generally helps, Start up Eclipse by running eclipse.exe, select workspace for the JSF examples

  • 5

    3 Tomcat Following steps explain set up of Tomcat on local workstation. This document uses Tomcat v7.0.12

    Download Download Tomcat from the following URL. Note: Tomcat Server version 7.0.12 are used for the examples. Download the binary zip file http://tomcat.apache.org/download-70.cgi

    http://tomcat.apache.org/download-70.cgi

  • 6

    Extract Extract the binary zip file to C:\ Drive

  • 7

    Configure Update the tomcat users file under /conf/tomcat-users.xml to add users for accessing the host manager.

  • 8

    Validate Validate that the server start up by running /bin/startup.bat

    Logon on to the server console by using the following URL: http://localhost:8080/

    http://localhost:8080/

  • 9

    Validate that Tomcat Manager is accessible, by clicking on the Manager App Link, enter the username password configured in the tomcat users xml file.

    You may use the tomcat manager to deploy the JSF application (WAR File).

  • 10

    4 Maven (Note**: Only applicable if planning to use the maven web application project for JSF Examples)

    You can skip this if you do not plan to use Maven.

    Download Download maven from the following URL, we are using Maven version 2.2.1 http://maven.apache.org/download.html

    http://maven.apache.org/download.html

  • 11

    Extract Extract Maven to C:\ Drive, need to set the \bin to the Path so that the mvn executable can be invoked from the command prompt. Type mvn version on the command prompt to validate the maven install

    Please consult maven documentation for further information, if inside a fire wall with no access to the internet to the maven global repository, local repository may need to be set up and versions of file may need to be installed manually.

    M2Eclipse Maven Plug-in for Eclipse Install M2Eclipse Maven Plug-in for eclipse which helps very much when working with Maven Projects Follow instructions available at the following URL http://m2eclipse.sonatype.org/installing-m2eclipse.html

    http://m2eclipse.sonatype.org/installing-m2eclipse.html

  • 12

    Alternatively use the Eclipse Marketplace option available in Eclipse Helios , Select Help Eclipse Marketplace option from the Menu and enter m2eclipse in the find input text box. Click on Install for Maven Integration for Eclipse.

  • 13

    5 Building the Web Application using Maven Project (Note**: Only applicable if planning to use the maven web application project for JSF Examples)

    Extract the project source code and navigate to the Maven Project Folder.

    From the Command prompt, navigate to the maven project and run mvn clean install to create the war distribution,

    This will create the war distribution under the target folder

  • 14

    The Maven Build will generate war file under Target folderas shown below,

  • 15

    6 Deploying the Web Application using Tomcat Manager App Deploy the war file to tomcat application server, using the tomcat manager app discussed in section 3. Both the Maven Generated War file from the Target Folder or the War file available in the RegularWebapp folder can be deployed using the Tomcat Manager Apps.

    Click on the hyperlinked JSFApps_Day1 in the manger app to launch JSF examples

  • 16

    7 Workspace Set up with Eclipse and Tomcat Start up Eclipse in a workspace (we will use C:\temp\temp\tests\workspace as an example).

    Create an instance of the Tomcat Server in the workspace. Select the Server Tab and Select New Server. Note: If the Server Tab is not visible, select / click on Windows Show View Servers from the Menu.

    Select the appropriate Tomcat Server, (we are using tomcat v7.0.12 for the example) Select the server and click on next.

  • 17

    Select the directory of the tomcat installation and click on finish to create the server Start the Server to validate that the server work, right click on the server and select start, or click on the start icon

  • 18

    7 JSF Code import from WAR File Click on File Import

    Select Web War file

  • 19

    Browse to the JSF Example war file and select the war file. Leave the rest default, click on next. Click on Next

  • 20

    Do not select any jar files, these will be imported as part of WEB-INF/lib Click on Finish, Build the project and run on server,

  • 21

    8 Set up workspace from Maven Project Note: This is applicable if planning to use Maven for building web application. Skip this step if not planning to use Maven or if already imported the source code as a WAR import. Please Required Maven Configuration as discussed in Step 4 must be completed for these. Select File Import from the Menu and then select Maven Existing Maven Projects from

  • 22

    Browse to the workspace and select the Maven Project. Click on ok, validate that the POM File is selected. Click on finish to import the Maven Project

  • 23

    By Default the Maven Project would be imported as a Java Project, we would need to add a Dynamic Web Application Facet for it to allows us to easy build and deploy to locally running server. (There are other workarounds for these like running tomcat using Maven Tomcat Plug-in or using the Maven Eclipse WTP Plug-ins, however to keep things simpler we will add project facets externally to our project.) M2Eclipse Plug-in allows to clean and install the project from menu options within Eclipse. Select Maven Install to validate that the project builds within Eclipse using the M2Eclipse Plug-in.

  • 24

    In order to facilitate running the Project on the locally installed Tomcat Server we would need to copy required libraries to the WEB-INF/lib folder. Copy Libraries from the Taget folder to the src/main/webapp/Web-Inf/lib folder. Example: C:\temp\temp\day1\MavenProject\JSFApp_Day1\target\JSFApp_Day1\WEB-INF\lib to C:\temp\temp\day1\MavenProject\JSFApp_Day1\src\main\webapp\WEB-INF\lib

  • 25

    Update the Project to include Dynamic Web Application Right Click on the Project and Select Properties,

    Select Project Facets, Then click on the Convert to faceted form..hyperlink.

  • 26

    Select Dynamic Web Model Check Box and the Click on the Further configuration available hyperlink. Enter src/main/webapp for Content Directory and then click on ok. Click on Apply / Ok to convert the project to Dynamic Web Module Facet.

  • 27

    Right Click on the project and Run on Server,