Tutorial on Integrating Eclipse and Tomcat This tutorial will guide you through the process of installation of Eclipse, Jakarta Tomcat, and an Eclipse Tomcat launcher plug-in that will integrate Eclipse and Tomcat. It will also guide you through a few examples that are designed to make sure the software has been installed correctly. Software Step 1. Install Java 2 Platform, Standard Edition (J2SE) Step 2. Install Eclipse IDE Step 3. Install Jakarta Tomcat Step 4. Install Sysdeo Eclipse Tomcat Launcher plugin Step 5. Configure Eclipse Examples Step 6 Create and execute a J Step 7. Create a new Tomcat Pr Step 8. Create and execute a J Step 9. Create and execute a S STEP 1: Install Java 2 Platform, Standard Edition (J2SE) Click on the "Watch a Viewlet" button in Step 1 of Gel Tutorial to view this step 1. Download the file here .
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Tutorial on Integrating Eclipse and Tomcat
This tutorial will guide you through the process of installation of Eclipse, Jakarta Tomcat, and an Eclipse Tomcat launcher plug-in that will integrate Eclipse and Tomcat.
It will also guide you through a few examples that are designed to make sure the software has been installed correctly.
Software
Step 1. Install Java 2 Platform, Standard Edition (J2SE)
STEP 1: Install Java 2 Platform, Standard Edition (J2SE)
Click on the "Watch a Viewlet" button in Step 1 of Gel Tutorial to view this step
1. Download the file here.2. Run the file j2sdk-1_4_2_05-windows-i586-p.exe.3. Install into default directory C:\j2sdk1.4.2_05 and accept default settings.
STEP 2: Install Eclipse IDE1. Download the file here2. Double click eclipse-SDK-3.0-win32.zip3. Extract to C:\eclipse
3. Select the Java option from the left hand tree view. Expand the Java element and select Installed JRE's.
4. Click "Add" and navigate to the JRE directory of the SDK (C:\j2sdk1.4.2_05\jre) .Input JRE name and click "OK".
5.Check the check box beside the JRE that you just added from the SDK you installed, as shown below. This sets this JRE as the default JRE to be used by Eclipse. You must do this for the Tomcat plugin to work. The Tomcat plugin requires that an SDK be the default JRE selected in these Eclipse preferences.
6. Set the Tomcat plugin preferences. First, select Tomcat from the left tree menu, then check Version 5.x, then click Browse to select Tomcat home (C:\jakarta-tomcat-5.0.28).
7. Select JVM Settings from the left tree menu, add tools.jar to Classpath.Then click OK.
STEP 6: Create and Execute a Java Applet
1. Select File > New > Project and a NewProject window will pop up, select Java Project, then click Next button.
2. New Java Project window will pop up, input the name of project, here "AppletDemo", then click Next button.
3. Keep it as default and click Finish button.
4. Select AppletDemo (project name) in the workspace and right click on it, then select New > File.
5. In the pop up window New File, input the name of applet, here "SimpleApplet.java", then click Finish button.
6. Add the following code to the file SimpleApplet.java and save it.
import java.awt.*; import java.applet.*;
public class SimpleApplet extends Applet { public void paint(Graphics g) { g.setColor (new Color(0,0,255)); g.drawString("This is a simple applet Demo", 50,50); }
}
7.Select SimpleApplet.java in the workspace and right click it, then select Run>Java Applet.
8. A AppletViewer window will pop up showing the running result.
9. Applet can also be viewed through a browser, to do this, you need edit a html file that contains the applet tag and applet class name (the applet class should be in the same directory, or else path should be included). Here is a example (in FrontPage editor).
10. Click the html file and the applet will show as below.
STEP 7: Create a new Tomcat Project
1. Select File > New > Project and select a new entry Tomcat Project , then press Next.
2.Give project a name such as TomcatProject and press Next.
3.Keep it as default and press Finish.
4.It will pop up a window, Click Yes.
5.A new project with a WAR structure is created in the workspace.
STEP 8: Create and execute a JSP
1. Select TomcatProject (created in step 6) in the workspace and right click on it, then select New > File. Give the file name JSPDemo.jsp and click Finish.
2.Add the following code to the file JSPDemo.jsp and save it.
<H2> If you're seeing this page via a web browser, it means you've integrated Tomcat and Eclipse successfully. Congratulations!</H2>
<H3> The current time is: <%out.println(new java.util.Date()); %> </H3>
</body></html>
3.Start Tomcat by pressing Start Tomcat button in the toolbar.
4.The log of startup of Tomcat will appear in the Eclipse console view.
5.Open a web browser and go to the URL http://localhost:8080/TomcatProject/JSPDemo.jsp . A page will load and you will get the following figure if followed all the above steps.
7. Select WEB-INF/ in workspace and right click it and select New > File.
8. A New File window will pop up and input the file name " web.xml" and click Finish button.
9. Input the following content that in the table
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN" "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
<web-app>
<servlet>
<servlet-name>SimpleServlet</servlet-name>
<servlet-class>SimpleServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>SimpleServlet</servlet-name>
<url-pattern>/SimpleServlet</url-pattern>
</servlet-mapping>
</web-app>
into the file web.xml, for this machine it pop up a Notepad window when Finish button clicked in step 7. So copy the content in above table into this Notepad window, then save it.
10. Press the Start Tomcat button in tool bar, after tomcat starts, open a browser and input the URL: http://localhost:8080/ServletDemo/SimpleServlet . The result will show as below: