Eclipse for Tomcat

download Eclipse for Tomcat

of 9

Transcript of Eclipse for Tomcat

  • 8/9/2019 Eclipse for Tomcat

    1/9

    Using Eclipse as a development environment withJakarta TomcatA quick approach to integrating Eclipse and Tomcat

    Level: Introductory

    Geoffrey Duck, Software Developer, IBM

    20 May 2004Updated 26 Jun 2006

    Using Eclipse as a development environment for Java technology is great. Using an EclipseTomcat plug-in can help to better organize and integrate your Java and Web development projects.This article will guide you step by step through the installation of Eclipse, Jakarta Tomcat, and anEclipse Tomcat launcher plug-in that will integrate them.

    Why Eclipse and Tomcat?

    Editor's note: New versions of Eclipse, Tomcat, and Java technology make some information in this articleobsolete. See "Developing Web applications with Tomcat and Eclipse," written by Nathan Good in May 2007 foran update of this article.

    I have been developing with Eclipse since its early days, and have found that it is one of the best things that everhappened to me for my Java development. Coming from a background of Java programming on Linux usingnothing but vi and a JDK, Java programming and debugging was a tedious task. Now, thanks to Eclipse, I canthrow together quick Java-based prototypes easily. My next thought was why not integrate my JSP developmentinto my Eclipse environment as well? Then I would be able to work more easily with my Java code and JSPs. Thegoal of this article is to save JSP developers time setting up Eclipse to work with Tomcat.

    Download the components

    There are several components involved when setting up Eclipse to work with Tomcat. These components areshown in Table 1.

    Table 1. Components and versions used in this article

    Download each of the components that you require. The sites where the files are available at the time this articlewas published are listed below in the Resources section.

    Eclipse IDE: The Eclipse IDE is used as the development environment for your JSP pages and Java files. Eclipseis an easy IDE to use, with many features that make for quick and painless Java programming and debugging.With the addition of the Tomcat plug-in, this IDE becomes a great tool for managing entire Web projects,including HTML and JSP pages, icons, and servlets.

    Java SDK: An SDK is required for the Tomcat Eclipse plug-in to function correctly. It does not necessarily have

    to be the Sun SDK, but it has to be an SDK, (you cannot use just a JRE as it will not work). There must be a Javacompiler present in the SDK in order for Tomcat to function with Eclipse.

    Tomcat: Tomcat is needed to drive your JSP pages. The Tomcat engine is a very good servlet engine that is freeand easy to install.

    Eclipse Tomcat Launcher plug-in by Sysdeo: This is just one of the many Eclipse plug-ins for Jakarta Tomcat.This is a good plug-in that saved me lots of time and integrated my Web projects with my Java code that I would

    Component Version

    Eclipse IDE 2.1.2

    Java SDK 1.4.1 1.4.1_06

    Tomcat 5.0.16

    Eclipse Tomcat launcher plug-in by Sysdeo Sysdeo Tomcat plug-in 2.2.1

  • 8/9/2019 Eclipse for Tomcat

    2/9

    usually use Eclipse to program.

    Installation

    Unzip all of the components

    Once you have downloaded what you need, the next step is to unzip each file. Unzip them and put them all in thesame directory to keep track of what you are unzipping.

    Copy the Tomcat plug-in into your Eclipse/plug-ins directory

    Once all of the files are unzipped, copy the Tomcat plug-in directory into the plug-ins directory in your Eclipsedirectory. The name of the directory that I unzipped from the Sysdeo zip file was com.sysdeo.eclipse.tomcat_2.2.1.I copied this entire directory into my Eclipse/plug-ins directory.

    Install the SDK

    Next, install the SDK you downloaded. The Tomcat Eclipse plug-in requires that the default JRE that you set up inyour Eclipse workspace is actually an SDK with a Java compiler. This is a requirement to use the Sysdeo Tomcatplug-in. Once the SDK is installed, you can start the Eclipse workbench.

    Configuration

    Set the SDK JRE as the default JRE for Eclipse

    Begin by starting Eclipse. You will have to configure several options from the workbench preferences pages. Openthe preferences dialog by selecting Window > Preferences, as shown in Figure 1.

    Figure 1. Eclipse preferences

    Select the Java option from the left-hand tree view. Expand the Java element and select Installed JRE's, as shownin Figure 2.

    Figure 2. JRE preference settings

    The Eclipse default JRE must be froman SDK

    It is a requirement that the JRE thatEclipse has set as its default is an SDK. Ifnot, the Tomcat plug-in will not work.

  • 8/9/2019 Eclipse for Tomcat

    3/9

    ClickAdd and navigate to the JRE directory of the SDK you installed during the installation phase of theconfiguration above, as shown in Figure 3. ClickOK.

    Figure 3. Adding a JRE to the Eclipse preference settings

    Check the check box beside the JRE you just added from the SDK you installed, as shown in Figure 4. This setsthis JRE as the default JRE to be used by Eclipse. You must do this for the Tomcat plug-in to work. The Tomcatplug-in requires that an SDK be the default JRE selected in these Eclipse preferences.

  • 8/9/2019 Eclipse for Tomcat

    4/9

    Figure 4. Setting the default JRE for Eclipse and Tomcat

    Set the Tomcat Home variable in the Tomcat preferences

    Next, we will set the Tomcat plug-in preferences. With the Preferences dialog still open, select Tomcat from theleft tree menu, as shown in Figure 5.

    Figure 5. Setting the Tomcat plug-in preferences

    Select the version of Tomcat that you installed from the top radio buttons. I used Tomcat V5.0.16 so I haveselected the last radio button option available, Version 5.x.

    Next, we have to set the Tomcat Home variable. Next to the Tomcat Home dialog box, clickBrowse. Browse tothe base directory of the Tomcat version that you unzipped and clickOK. The Configuration file will beautomatically selected and filled in for you. If you wish to select another configuration file for Tomcat instead ofthis one, you can browse to that file now. Otherwise the default value will work fine.

    We have now completed the minimal requirements to start and run Tomcat using Eclipse and the Sysdeo TomcatLauncher plug-in. Browse through the remaining preferences for Tomcat in the Eclipse preference dialog. You willnotice that there are many other options available to you in the Tomcat preferences. For example, addingparameters to the JVM used by the Tomcat server, selecting Java projects from your workspace to add to theTomcat classpath, as well as settings to allow the use of the Tomcat management application.

  • 8/9/2019 Eclipse for Tomcat

    5/9

    Testing Tomcat and Eclipse together

    Create a new Tomcat Project

    To test the integration of Tomcat and Eclipse, we will start by creating a new project. Select File > New > Projectand examine the new project wizards contents. There is a new entry available in the Java section of this projectwizard. Tomcat Project is a new option available (see Figure 6). Select it and clickNext.

    Figure 6. Creating a new Tomcat project

    Give your new Tomcat project a name. For example, TomcatProject, as shown in Figure 7. ClickNext.

    Figure 7. Setting the Tomcat project name

  • 8/9/2019 Eclipse for Tomcat

    6/9

    Here you see that you may specify the name of the Context for your Web project and also that you may specify asubdirectory as the webapplication root. We will keep the defaults for now (see Figure 8). ClickFinish.

    Figure 8. Setting the Tomcat webapplication root directory

  • 8/9/2019 Eclipse for Tomcat

    7/9

    A new project with a WAR structure is created in your workspace, as shown in Figure 9.

    Figure 9. Tomcat project created

    Create a JSP file to test

    The easiest way to test your installation is to create a new file in the root folder of your WAR project. Create a newfile, call it "index.jsp". To do this, select your project in the workspace and right click on it. Select New > File.Name it "index.jsp" as shown in Figure 10 and clickFinish.

    Figure 10. Create an index.jsp file to test your configuration

    Add the content shown in Listing 1 to your index.jsp file and save it.

    Listing 1. Sample index.jsp

    Todays date is and this jsp page worked!

  • 8/9/2019 Eclipse for Tomcat

    8/9

    Start Tomcat using the Sysdeo plug-in

    Now for the big moment. To start the Tomcat server, simply press on the Start Tomcat button that was added toyour toolbar, as shown in Figure 11. You can also select the Tomcat menu from the main menu bar and selectStart Tomcat.

    Figure 11. Start the Tomcat server using the Sysdeo Tomcat plug-in

    The Tomcat server will start and its startup text will appear in the Eclipse workbench's Console view, as shown inFigure 12. Examine the startup log and watch for any errors.

    Figure 12. Tomcat's startup information is displayed in the Eclipse Console view

    Launch a browser and view your index.jsp file

    When the server has started, launch a Web browser. Go to http://localhost:8080/TomcatProject. A page shouldload and you should get a message similar to this one:

    Todays date is 30 and this jsp page worked! (The 30 appears on my screen because

    today is the 30th)

    Summary

    You should now have Eclipse set up and configured to work with Jakarta Tomcat. You now have the power todevelop and test quick JSP's with integrated Java code, using a great IDE that will help improve your productivity.Using Eclipse to program Java code and having it integrated with Jakarta Tomcat will make JSP development funand easy.

    ResourcesLearn

    New versions of Eclipse, Tomcat, and Java technology make some information in this article obsolete. See"Developing Web applications with Tomcat and Eclipse," by Nathan Good in May 2007 for an update ofthis article.

    "What is Eclipse and how do I use it?" provides a lot of information for users new to Eclipse.

    "The Tomcat story" contains a great background look at Jakarta Tomcat.

    The Jakarta Tomcat Web site contains a plethora of information about Tomcat.

    Expand your Eclipse skills by visiting IBM developerWorks' Eclipse project resources.

    Browse all of the Eclipse content on developerWorks.

    Visit the developerWorks Open source zone for extensive how-to information, tools, and project updates tohelp you develop with open source technologies and use them with IBM's products.

  • 8/9/2019 Eclipse for Tomcat

    9/9

    Stay current with developerWorks technical events and webcasts.

    Get products and technologies

    Download Eclipse from Eclipse.org.

    Download Tomcat from the Jakarta download page.

    Download the Java SDK V1.4.1 from the Sun Web site.

    Download the Sysdeo Tomcat plug-in from the Sysdeo Web site.

    See the latest Eclipse technology downloads at IBM alphaWorks.

    Innovate your next open source development project with IBM trial software, available for download or onDVD.

    Discuss

    Get involved in the developerWorks community by participating in developerWorks blogs.

    About the author

    Geoff Duck is a software developer for IBM Canada Ltd and works in the IBM center for e-business innovation inBurnaby, BC, Canada. Geoff specializes in Java programming and design, as well as Web-based applications.