Tutorial On Integrating Eclipse and Tomcat
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 Examples
Step 1. Install Java 2 Platform, Standard Edition (J2SE) Step 6 Create and execute a Java Applet
Step 2. Install Eclipse IDE Step 7. Create a new Tomcat Project
Step 3. Install Jakarta Tomcat Step 8. Create and execute a JSP
Step 4. Install Sysdeo Eclipse Tomcat Launcher plugin Step 9. Create and execute a Servlet
Step 5. Configure Eclipse
2. Select Window<Preferences
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.*;
7.Select SimpleApplet.java in the workspace and right click it, then select Run>Java
Applet.
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.
<html>
<title>JSP Demo</title>
<body bgcolor="blue" text="white">
<H2> If you're seeing this page via a web browser, it means you've integrated Tomcat
and Eclipse successfully. Congratulations!</H2>
</body>
</html>
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.
1. Select File > New > Project. Then New Project window will pop up, select
Tomcat Project then click Next button.
2. In the New Tomcat Project window, input the project name, here use
"ServletDemo",then click Next button.
4.Select WEB-INF/src in workspace and right click it and select New > File.
5.In the pop up window New File, input file name "SimpleServlet.java" and click Finish
button.
6. Input the following code in to the file SimpleServlet.java and click Save button in
toolbar.
import java.io.PrintWriter;
//import javax.servlet.*;
performTask(request, response);
}
public void doPost(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
throws javax.servlet.ServletException, java.io.IOException {
performTask(request, response);
}
public void performTask(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
{
try
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("This is a Simple Servlet Demo");
}
catch(Throwable theException)
{
//theException.printStackTrace();
}
}
}
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.
<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: