Pages

Friday, July 1, 2011

Eclipse Plugin for Tomcat Server with Hello World

The following site seems to be a good source for downloading and installing a Tomcat Server plugin for Eclipse.
All you got to do is download this plugin and proceed with the following procedure to install them
  • This plugin does not contain Tomcat.
    (Download and install Tomcat before using this plugin).
    This is a design choice not to include Tomcat in the plugin distribution, this way the same plugin version can works with any Tomcat version.
  • Download tomcatPluginVxxx.zip
  • Unzip it in :
    - Eclipse_Home/dropins for Eclipse 3.4, 3.5 and 3.6
    - Eclipse_Home/plugins for Eclipse 2.1, 3.0, 3.1, 3.2 and 3.3
  • Plugin activation for Eclipse 3.x :
    - 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.
    This JRE must be a JDK (This is a Tomcat prerequisite).
The plugin sets itself Tomcat classpath and bootclasspath. Use Preferences -> Tomcat ->JVM Settings, only if you need specific settings.

 
The following site contains an awesome example/illustration that will help you get started with the plugin on eclipse
Once you have installed the plugin, the following are the things that you need to have a closer look at.
You would be able to see 3 icons added to the eclipse tool bar which is as illustrated in the following image . And these are  self explanatory

Go to Windows->Preferences. This will bring up the Preferences dialog box, that will contain a whole new section as highlighted in the navigation section.  And on the right side you have to choose your Tomcat version and provide its installation path as Tomcat home

Specifying the tomcat home helps the plugin assume the path of the server.xml file which in my case is as follows

Well you may not do much with this one for the time being, but its always good to know right J
Once that’s done, Navigate to the Tomcat Manager App option available in the left menu of the preferences window as illustrated by the following image

Now when you provide a ManagerApp username and ManagerApp password, and click on “Add user to tomcat-users.xml”, this will update the corresponding xml file as illustrated by the following image


As you can see, the username and password are abruptly visible and hence exercise caution in handling these files to avoid security breaches
Once the above stuffs are complete now create a new project by right clicking the navigator as illustrated in the following images
 
So create a new tomcat project as mentioned above and now name them as per your requirement and in this case it is “HelloWorld” and create your servelet classes as illustrated in the following image. Mind the folder structure :)
 

Now create your web.xml file in the same WEB_INF folder and not in the src folder that is highlighted above with servelet mappings to class file and url, in my case the web.xml file contains
DOCTYPE web-app PUBLIC
  '-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN'
  'http://java.sun.com/dtd/web-app_2_3.dtd'>
<web-app>
  <servlet>
    <servlet-name>helloservlet-name>
    <servlet-class>HelloServletservlet-class>
  servlet>

  <servlet-mapping>
    <servlet-name>helloservlet-name>
    <url-pattern>/hellourl-pattern>
  servlet-mapping>
web-app>
Now save all your work. Start your tomcat server and check out the following url,
In my case the pages looks like the following


The materials contained here are more exhaustive than the one posted here.

Hope this helps :)

 
 
 

No comments:

Post a Comment