Setting Up Eclipse and Tomcat

infestationwatchΛογισμικό & κατασκευή λογ/κού

28 Οκτ 2013 (πριν από 3 χρόνια και 1 μήνα)

51 εμφανίσεις

Setting Up Eclipse and Tomcat


Bryan Duggan


4th December 2002


This document explains how to set up Eclipse (a Java IDE) to edit, compile and run
Java code (including JSP's). It also explains how to set up Eclipse to edit and debug
servlets (generated fro
m JSP's) and how to install and configure an optimal Tomcat
and JDK environment. Note the Eclipse environment will work best on PC's with a
minimum of 256Mb of RAM.


1.

Uninstall all existing versions of the JDK and JRE. Go to Control panel, and add
remover p
rograms applet and look for things like "Java 2 Runtime
Environment..." etc.

2.

Uninstall old versions of Eclipse or JBuilder. To uninstall JBuilder, go to the add
remove programs applet in the control panel. To uninstall Eclipse, delete the
Eclipse directory
.

3.

Install the JDK 1.4 from the CD. The installer is called:


j2sdk
-
1_4_1
-
windows
-
i586.exe


Select the defaults when installing.


4.

Set the JAVA_HOME and PATH environment variables to point to the JDK. To
do this on Windows 2000, go the control panel, go to

the System applet, go to the
Advanced tab and press the Environment Variables button.

























5.

Click on the System variables list and either edit or add the variables
JAVA_HOME and PATH to point to the JDK. If you installed the JDK to
C:
\
j
2sdk1.4.1, (the default), then make JAVA_HOME = C:
\
j2sdk1.4.1


Add C:
\
j2sdk1.4.1
\
bin to the front of your PATH variable. You should remove
any other references to previously installed JDK's from your path at this stage
also.

6.

Install Tomcat, by running jaka
rta
-
tomcat
-
4.1.12.exe. When you run this program,
it will want to install to somewhere like:


C:
\
Program Files
\
Apache Group
\
Tomcat 4.1


I suggest you change this to install to c:
\
Tomcat for simplicity.


Also when installing you will be prompted to enter an

administrator password for
your Tomcat installation. I suggest you choose admin, admin for the user name
and password.

7.

Set the TOMCAT_HOME environment variable as described in steps 4 & 5 to
point to your Tomcat folder. Set it to be c:
\
Tomcat

8.

Next you nee
d to add some lines to your c:
\
Tomcat
\
Conf
\
web.xml file to enable
JSP debugging in Eclipse. Find the part of the file which reads:



<servlet>


<servlet
-
name>jsp</servlet
-
name>


<servlet
-
class>org.apache.jasper.servlet.JspServlet</servlet
-
class>


<init
-
param>


<param
-
name>logVerbosityLevel</param
-
name>


<param
-
value>WARNING</param
-
value>


</init
-
param>


<load
-
on
-
startup>3</load
-
on
-
startup>

</servlet>


And add the following lines in bold:



<ser
vlet>


<servlet
-
name>jsp</servlet
-
name>


<servlet
-
class>org.apache.jasper.servlet.JspServlet</servlet
-
class>



<init
-
param>


<param
-
name>classdebuginfo</param
-
name>


<param
-
value>true</param
-
value>


</init
-
param>



<init
-
param>


<param
-
name>logVerbosityLevel</param
-
name>


<param
-
value>WARNING</param
-
value>


</init
-
param>


<load
-
on
-
startup>3</load
-
on
-
startup>


</servlet>

9.

Test your JDK and Tomcat installation by r
unning Tomcat and looking at the
default web page in Integret Explorer. Start a command promt and navigate to
C:
\
Tomcat
\
Bin. Run startup.bat. If everything has been installed correctly, you
should should see a second DOS window open, like this one:


















10.

Check to make sure you can view pages in Tomcat by going to:


http://localhost:8080/index.jsp


in your web browser. You should be able to view the default page:




















11.

Shutdown Tomcat by running: shutdown.bat from the c:
\
Tomcat
\
Bi
n directory.

12.

Install Eclipse by unzipping all the files in the ZIP file to your C:
\

Drive. This file
contains paths, so just choose C:
\

when unzipping:













13.

Next install the Tomcat plug
-
ins for Eclipse. First unzip the files in the zip file
\
Eclips
e Plugins
\
jasperDebugPatchV4.1.12.zip to
c:
\
Tomcat
\
common
\
classes

14.

Then unzip the file:
\
Eclipse Plugins
\
tomcatPluginV201.zip to
c:
\
Eclipse
\
plugins

15.

Now unzip the file:
\
Eclipse Plugins
\
net.sf.solareclipse_0.3.1.bin.dist.zip to
c:
\
Eclipse.


Be very careful
about that you unzip these files to these exact locations
specified above!!

16.

Now start Eclipse...After a few seconds you should get the main Eclipse window:




17.

If you get a message about new updates, choose yes when asked to open the
update manager and ch
eck the option 4th December... and click finish and restart
your environment:



18.

You must now configure the Tomcat plugin for Eclipse. Go to Window |
Preferences | Tomcat. Click on Version 4.1.x and change Tomcat Home to point
to c:
\
Tomca
t:
































19.

Now click on JVM settings and select jre1.4.1 as the JDK.

20.

The Eclipse environment is organised around projects and perspectives.
A
perspective defines the initial set and layout of windows in the environment. You
can swit
ch perspectives by clicking on the perspective toolbar on the left hand
side.

21.

Create a new project by going File | New | Project, select Java and then Tomcat
Project. Give the project a name (MyTestProject) and choose a place to store the
project or accep
t the default:





22.

Press the next button and check the option "Can update server.xml".




23.

Now press finish, to finish creating your project. Your project window will be
updated to look like this:




24.

Now create a new
JSP by select MyTestProject, right click on the mouse button
and choose New | File. Give the file the name Test1.jsp and click

25.

Click on the newly created JSP file and put in some JSP code. For example:




26.

Save your file.

27.

To test your JS
P, choose Tomcat | Start Tomcat. Your project will switch to the
debug perspective.

28.

Go to the URL http://localhost:8080/MyTestProject/Test1.jsp in your browser and
you should get a web page with Hello world! on it.

29.

To debug the servlet you must set a brea
kpoint in the generated Java file. Go to
the work folder of your project and hit F5 to refresh the folder (switch back to the
Resource Perspective first). Now find the generated file for your JSP and set a
breakpoint on the line you want to debug by pressi
ng Shift Crtl + B. It should be
also possible to debug the JSP itself, but so far I havn't managed to get it working.

30.

Any problems with the above, first do a search in http://groups.google.com or
http://www.jguru.com.

31.

The Eclipse environment comes with ex
cellent tutorials and online help, which
you should read. It will tell you how to set up packages, add files and add JAR's to
the classpath etc. Also, there are many more useful eclipse plugins available on
the web.

32.

Good luck and happy programming!