Prerequisites:

Java 6 SDK

Apache Tomcat (see TomcatConfig)

Setup:

(reference: http://www.ibm.com/developerworks/opensource/library/os-eclipse-tomcat/ )

Install Eclipse using Yast Software Management. Before you can create a web project, you need to install the J2EE and Web Development plug-ins.

* With the Eclipse IDE running, select Help > Software Updates > Find and Install.

* Select Search for New Features to Install, then click Next.

* Select the Europa Discovery Site, then click Finish.

* A list of mirrors will open. Select the Georgia Tech Software Library.

* From the list under Europa Discovery Site, check the Web and J2EE Development box. The wizard immediately warns you that you're missing dependencies. Click Select Required, and these warnings should disappear. Some or all of the components in the Graphical Editors and Frameworks and Models and Model Development categories are selected because they're required for the installation of the Web and J2EE plug-ins.

* Click Next to continue, and license agreements appear for each feature you've selected. If you agree with the licenses, accept them and follow the wizard through the rest of the process. When the IDE is finished installing the plug-ins, it asks you to restart Eclipse in order for the changes to take effect. Be sure you restart the IDE before continuing.

* After you restart the IDE, the new features are available to begin developing dynamic Web projects.

Create New Web Project (Tomcat setup and test)

* From the Eclipse IDE, select File > New > Project to view the project wizards. Choose Dynamic Web Project from the list.

* Under Target Runtime, you see <None>, because you haven't created a runtime yet for Apache Tomcat. Click New to open the New Target Runtime Wizard. Select Apache Tomcat V5.5 from the Apache folder, then click Next.

* Click Browse to locate the base folder for your Apache Tomcat configuration. Instead of workbench default JRE, click Installed JREs and select the Sun JDK 6. Click Finish to create the runtime configuration.

* You're asked if you want to switch to the J2EE Perspective. It's a good idea to answer yes because that perspective includes views like the Servers view, which help to start and stop Tomcat later. You can always open the Servers view by selecting Window > Show View.

* In the Servers view is a view that contains nothing. This view is for application and Web servers; it lets you control them and monitor their status. To control Tomcat directly from the IDE, add a reference to Tomcat by selecting New > Server from the context-sensitive menu. The New Server wizard will default to the Apache Tomcat V5.5 runtime you just created.

* Click Next. You're asked whether you want to add projects to the server. Select the project you created in the previous steps, then click Add.

* Click Finish to close the wizard. Now the Servers view contains the Tomcat V5.5 Server with the project under it.

* For testing purposes, create a jsp: Right-click the project name in the Project Explorer view and select New > JSP.

* Make sure the parent folder is WebContent and name the file something like index.jsp. Click Finish to create the page using the default template. If you click Next, you can choose different templates to use (such as HTML or XHTML) for the new page. The defaults are fine for this test.

The page code shown below displays a simple date so you can see it working:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"[[BR]]
pageEncoding="ISO-8859-1"%>[[BR]]
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"[[BR]]
"http://www.w3.org/TR/html4/loose.dtd">[[BR]]
<html>[[BR]]
<head>[[BR]]
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">[[BR]]
<title>My Title</title>[[BR]]
</head>[[BR]]
<body>[[BR]]
<% java.util.Date d = new java.util.Date(); %>[[BR]]
<h1>[[BR]]
Today's date is <%= d.toString() %> and this jsp page worked![[BR]]
</h1>[[BR]]
</body>[[BR]]
</html>[[BR]]

* Deploy the page: Now that the test page is complete, use Eclipse to redeploy it to Apache Tomcat. In the Servers view, notice that State is set to Republish. That is because changes have been made since the project was last deployed to the server. Right-click the server and select Publish from the menu. The state changes to Synchronized once the project has been deployed to the server.

* With the project successfully deployed and the server started, open a browser and navigate to http://localhost:8080/[ProjectName]/filename.jsp (where [ProjectName] is the name of the dynamic Web project you created). Project and file names are case sensitive. The new Web page you created appears, and the date should be current. If you refresh the page, the date changes.

Create a Tomcat Project and Deploy a Servlet

The instructions to create a HelloWorld? Servlet on Tomcat can be found at: http://keyboardsamurais.de/2004/01/15/tomcat_tutorial_helloworld_for_complete_fools_-_english/

Following the steps enumerated in the webpage mentioned above, Eclipse gives the following error:

HelloWorld cannot be built as the following JAR files are missing:
$HOME/tomcat/lib/common/jasper-runtime.jar
$HOME/tomcat/lib/common/java-api.jar
$HOME/tomcat/lib/common/servlet-api.jar 

The above mentioned three JAR files are named differently in $HOME/tomcat/lib/common. This is because tomcat has been installed through the RPM of Yast in Open Suse 10.3. Tomcat installed from the Apache website -- http://mirror.candidhosting.com/pub/apache/tomcat/tomcat-5/v5.5.25/bin/apache-tomcat-5.5.25.tar.gz does contain the named JAR files as required in Eclipse.

The conflict between installing tomcat through RPM and Apache's official site is to be resolved.

As a temporary workaround do the following steps to successfully build Tomcat projects in Eclipse--

  1. Install tomcat in $HOME/dist from http://mirror.candidhosting.com/pub/apache/tomcat/tomcat-5/v5.5.25/bin/apache-tomcat-5.5.25.tar.gz
  2. Unpack the tomcat distribution in $HOME. This unpacks as -- $HOME/apache-tomcat-5.5.25
  3. Unset the environment variables "CATALINA_HOME" and "CATALINA_BASE"
  4. From the same shell, launch eclipse
  5. Set Tomcat home : Workbench -> Preferences, select Tomcat and set Tomcat home as $HOME/apache-tomcat-5.5.25
  6. Build the HelloWorld? Servlet according to the instructions in the webpage - http://keyboardsamurais.de/2004/01/15/tomcat_tutorial_helloworld_for_complete_fools_-_english/

Sysdeo Tomcat Plugin for Eclipse

The Sysdeo plugin will allow you to start and stop Tomcat from within Eclipse.

  • Download tomcatPluginV321.zip from http://www.eclipsetotale.com/tomcatPlugin.html.
  • Unzip it in your_Eclipse_Home/plugins.
  • Plugin activation for Eclipse:
    • launch eclipse once using this option : -clean
    • if Tomcat icons are not shown in toolbar : select menu Window -> Customize Perspective...>Commands, and check Tomcat in Available command groups
  • Set Tomcat version and Tomcat home : Workbench -> Preferences, select Tomcat and set Tomcat version and Tomcat home (Tomcat version and Tomcat home are the only required fields, other settings are there for advanced configuration).
  • This plugin launches Tomcat using the default JRE checked in Eclipe preferences window. To set a JDK as default JRE for Eclipse open the preference window : Window -> Preferences -> Java -> Installed JREs.
  • The plugin sets its own Tomcat classpath and bootclasspath. Use Preferences -> Tomcat ->JVM Settings, only if you need specific settings.

Important links on configuring Eclipse for running web applications

How to deploy servlets on tomcat

Integrating GridSphere with Eclipse

reference: https://mams.melcoe.mq.edu.au/zope/mams/pubs/Installation/gridsphere-howto.pdf/view

  • Download GridSphere and untar/unzip it to a temporary working directory.
  • In Eclipse, create a new Tomcat project called gridsphere under the context name “/gridsphere”and set the subdirectory to set as web application root to /webapp. Untick the option to update the server.xml.
  • Right-click on the new project and select the Import option. Select File System and navigate to the root directory of the unzip/untar gridsphere directory. Import everything, by ticking the gridsphere root folder. Select "Create selected folders only." If you are integrating Shibbolized Gridsphere with Eclipse, then do not overwrite .project file. Otherwise, you won't get a complete list of project properties, as described in the next step. Once done, you should see the at least the lib, src, projects, webapp and webapps folders under the project.
  • Right-click on the gridsphere project and select the "Properties" option.
  • Under Java Build Path, Source tab make sure the only folder is gridsphere/src.
  • Under Libraries, add all the jars found under gridsphere/lib.
  • Also under Libraries, add an external jar called ant.jar, found under /usr/share/ant/lib.
  • Select the build.xml file, right-click on it, and select the second run as “Ant Build” option. A new build configuration window will popup. Under the Environment, add a new variable called CATALINA_HOME. The value is "/<your home>/apache-tomcat-5.5.25", and select to append to the native environment.
  • The first time you run Tomcat, you need to select setenv, and install option under the targets tab of the Ant Build option. Click apply and run to install gridsphere to your tomcat server.
  • Modify the ant target to “setenv, deploy”, so that subsequent ant builds do not delete the Gridsphere database.