serving the solutions day and night

Pages

Sunday, February 20, 2011

Eclipse and Tomcat Confirguration, Create War.

1)Download and extract Eclipse IDE for Java EE Developers

2)Download and extract or install Apache Tomcat

3)Open your browser, type http://localhost:8080 and verify tomcat is running.


Tomcat Server Configuration
4)Open your Eclipse IDE, go to the Window menu -> Preferences sub menu.

5)Select Server -> Runtime Environments, then press 'ADD' button, the New Server Runtime Environment window opens.


6)Select Apache Tomcat V7.0


7)Press Next button to set Tomcat and JRE installed folder. Click Browse button to set tomcat installed folder, then pick JRE from list box (or click Installed JREs button to add new JRE from folder) and press Finish button.


8)Press OK to configured Tomcat server environment.

Create HelloDaynight Servlet

9)Goto File -> New -> Dynamic Web Project, type Project Name, select Target runtime (Apache Tomcatr v7.0), Dynamic web module version and configuration (all these 3 values are pre populated based on the previous Tomcat configuration).


10)Goto New->Servlet, Create Servlet window shows, type package and class name, press Finish button to create new HelloDaynight Servelt.



11)Goto doGet() method, enter your Servlet code, right click, select Run As - > Run on Server, Run on Server window opens, select Tomcat server, and press Finish button. Finally you can see url http://localhost:8080/New_Daynight_Project/HelloDaynight and servlet ouput in the Eclipse browser window. Open any browser, copy the above link to see output.




Create index.jsp JSP
12)Goto File -> New -> other -> web -> JSP File, press Next button, to choose project WebContent folder, enter file name, press Next button to choose New JSP File (html) template. index.jsp file created.


13)Add content in between body tag and save it, right click, select Run As - > Run on Server, Run on Server window opens, select Tomcat server, and press Finish button. Finally you can see url http://localhost:8080/New_Daynight_Project/index.jspt and servlet output in the Eclipse browser window. Open any browser, copy the above link to see output.

Create WAR, deploy to tomcat host server

14)Goto File->Export->Select Web->Choose WAR file, choose tomcat webapps destination folder to create and save war file, press to finish button.


15)Start Tomcat service, the project will be deployed.


16)Open your browser, type http://localhost:8080/nep/ to verify jsp page and
http://localhost:8080/nep/HelloDaynight to verify servlet page.

Start/Stop and Add/Remove Existing Project

17)Click on the Servers tab at the bottom, right click on 'Tomcat v7.0 Server at localhost', choose "Start" ans "Stop" the server.

18)Choose "Add and Remove...", to add available project.

19)If available project area is not listed existing java web project, than right click on the java web project, choose Properties->Project Facets, Click the link 'convert...', it shows Project Facts configuration page.

20)Check Dynamic web module, JavaScript, Java, if you need other Facets, then check it.
Click on the 'Runtimes' tab, check 'Apahce Tomcat v7.0'. Press to OK button. Now go to step 18 to add project.

How to specify which folder is served from the project?

21) In the project -> .settings folder, file named 'org.eclipse.wst.common.component' that contains an XML fragment like this:


<project-modules id="moduleCoreId" project-version="1.5.0">
  <wb-module deploy-name="PROJECT_NAME">
    <wb-resource deploy-path="/" source-path="/"/>
    <wb-resource deploy-path="/" source-path="/WebContent"/>
    <wb-resource deploy-path="/WEB-INF/classes" source-path="/WEB-INF/src"/>
    <property name="context-root" value="ggold"/>
    <property name="java-output-path" value="/ggold/WEB-INF/classes"/>
  </wb-module>
</project-modules>

You should be able to change the source-path under wb-resource to your share folder. You can set it any folder.

22)Through Eclipse, right click on your project->properties->Click on 'Deployment Assembly'->
Add... Folder -> Next -> Navigate to source folder - >Finish . You can set it only for folder under WebContent or src.

No comments: