Myfaces application can be configured in eclipse and launched using tomcat/jetty servlet container. Lets assume a general web application directory structure:
<root> +---lib +---persistence | +---src | +---java +---service | +---src | +---java +---web +-----src | +---java +-----webapp +---WEB-INF | +---classes | +---lib | +---web.xml | +---faces-config.xml +---<view pages>
The <root>/lib folder contains Myfaces jars (Let <root> folder be c:\workspace\myproject). Its may be a good idea to download all latest commons jars and put in a subdirectory under lib (eg: latest version of commons-logging.jar will be used by Myfaces as well as hibernate, avoiding maintainence of different versions). Install the following:
- j2sdk 1.5
- eclipse sdk 3.1 (c:\eclipse)
- tomcat 5.x if you want to use tomcat(c:\applications\Tomcat5.x)
- jetty 5.1 if you want to use jetty(c:\applications\jetty5.1)
Following steps are common whether configuring for tomcat or jetty
- create a new java project in eclipse.In project properties window do add all the source code in the source path.
make the "destination path" as <root>/web/webapp/WEB-INF/classes in project properties.
create a new user library and add all jars under <root>/lib folder to it recursively.
Now the project should be compiling without errors and all class files should get generated under <root>/web/webapp/WEB-INF/classes.
Configuring in Tomcat
- Any of these two eclipse plugins for tomcat need to be installed: "sysdeo" or "wtp tomcat plugin". We will cover Sysdeo plugin as it is easy to configure(wtp1.0 tomcat plugin enforces a predefined directory structure).
- unzip sysdeo plugin into c:\eclipse\plugins directory and restart eclipse.
go to windows --> preferences --> Tomcat
- select the tomcat version and enter the Tomcat home (c:\applications\Tomcat5.x). Click OK.
- Click on the start tomcat icon in the eclipse toolbar to startup tomcat. ( make sure its running)
Now copy all jars under <root>/lib to c:\applications\Tomcat5.x\common\lib. directory structure under <root>\lib needs to be flattened up when copying to tamcat's common lib folder
- create a new myproject.xml file in C:\applications\Tomcat5.x\conf\Catalina\localhost directory. Following needs to be entered:
<?xml version='1.0' encoding='utf-8'?> <Context docBase="${catalina.home}/../../workspace/myproject/web/webapp" path="/myproject"> <Logger className="org.apache.catalina.logger.FileLogger" prefix="localhost_myproject_log." suffix=".txt" timestamp="true"/> </Context>
- restart tomcat from eclipse by pressing the restart icon.
localhost:8080/myproject/index.faces shows welcome page.
Configuring in Jetty
Install jetty launcher plugin from http://jettylauncher.sourceforge.net/updates and restart eclipse.
Right click on project --> Run as --> Run
- Select "Jetty Web" on the left hand pane, and click new button at the bottom left hand corner.
- In the screen that shows up on right hand pane, enter following:
jetty home: c:\applications\jetty5.1
webapp root dir: web/webapp
contextname: myproject
http host: localhost
- Click on "Apply". Click "Run".
localhost:8080/myproject/index.faces shows welcome page.