Eclipse Web Tools Platform

We are going to use an extension of the Eclipse platform to help us write, deploy, and run this chapter's applications. To be more specific, we are going to use the Eclipse Web Tools Platform (WTP), which is a set of plugins containing tools for supporting the development and deployment of Java web-based applications. Among other things, using WTP, you can start, stop, and restart the web server from within Eclipse. Thus, you do not need to switch back and forth between Eclipse and Tomcat (or the server of your choice) as you deploy web applications. For an overview of all Eclipse WTP's plugins and their features, visit the project's site: http://www.eclipse.org/webtools/.

You can download Eclipse WTP as a binary distribution from the project site: http://download.eclipse.org/webtools/downloads/. Nevertheless, this is not the best approach. The most straightforward approach to get WTP up and running is to download the Eclipse version that is prepackaged with the WTP components: Eclipse IDE for Java EE Developers on the www.eclipse.org/downloads page. However, most Eclipse versions do not ship with Eclipse WTP. As of this writing, only Eclipse 4.2 has a version that ships with WTP. If you need to use Eclipse 3.8 with WTP, you will have to use the method explained in this chapter.

Alternatively, if you downloaded the Eclipse version for Java development, you can install Eclipse WTP by updating your IDE via the Eclipse Update Manager, which is also an easy approach.

In order to use the Eclipse Update Manager to install Eclipse WTP, click on Help, and then on Install New Software. You need to type the location of a software site or select an existing one using the Work with combo at the top of the installation window. Go ahead and type the following in the Work with field:

http://download.eclipse.org/releases/juno/ (as shown in the following screenshot):

Eclipse Web Tools Platform

The preceding screenshot shows a list of available updates. As you browse the available software options, select the item Web, XML, Java EE and OSGi Enterprise Development, as shown in the previous screenshot. Make sure to check all items belonging to the Web, XML, Java EE and OSGi Enterprise Development item but PHP Development Tools (PDT) SDK Feature. After selecting the desired items, click on Next to install them. The following is what happens when you click on Next:

  • Once you hit Next, Eclipse validates your selections against your installed software. Also, Eclipse takes care of managing dependencies between the selected plugins. Thus, if a selected item requires another software item to operate, the required software will also be downloaded automatically. That is one of the reasons that using Eclipse Update Manager is an easier approach.
  • After you agree with the license agreement (select the I accept the terms of the license agreements radio button), Eclipse starts installing the chosen extensions.
  • After downloading everything, Eclipse will prompt you to restart; click on Yes to restart Eclipse.

If everything turns out well, you will be greeted with the following screenshot (something similar to what you saw when you opened Eclipse for the first time):

Eclipse Web Tools Platform

Configuring the server

Now, you have successfully installed Eclipse WTP. However, there is still some configuration to be done before jumping headlong into developing web applications using Eclipse. The next step is setting Eclipse WTP up by indicating which server you want to use and where it is installed (that is, where you unzipped Tomcat). Let's begin by telling Eclipse which server we want to use. To do so, you need to navigate to Preferences | Server | Runtime Environments. You will see the Preferences window as shown in the following screenshot. During development, you will be back to this window whenever you feel the need to add or remove servers:

Configuring the server

Next, press the Add… button on the right-hand side of the dialogue box. A window containing a list of servers will pop up. Apart from Tomcat, Eclipse WTP supports a number of other servers. In case you do not find the desired server in the list, you can download additional server adapters (as shown in the top-right corner of the window in the following figure). To select Tomcat, expand the Apache folder, and then pick your desired version of Tomcat. Throughout this chapter we are going to use Apache Tomcat v7.0 (as shown in the following screenshot). After selecting the proper version of Tomcat, you should hit Next:

Configuring the server

Apart from selecting the desired server runtime environment, you also need to indicate its installation directory. As shown in the following screenshot, in order to inform Eclipse where Tomcat is installed, you need to type the root directory where you unzipped Tomcat. In fact, you can browse to and select your Tomcat root directory by clicking on Browse…. For instance, in the following screenshot, the Tomcat root directory is /usr/local/apache-tomcat-7.0.33. Afterwards, click on Finish.

Configuring the server

Tip

Make sure that the field Workbench default JRE (in the bottom of the previous figure) is pointing to the desired JDK version.

The next step is to create a new Tomcat server within Eclipse. To do so, navigate to Window | Show View | Other…. Then click on the Server option to expand it, as shown in the following screenshot. Select Servers, and press OK:

Configuring the server

Now, as you can see in the following screenshot, the server view displays the status of Tomcat. Through this view you can start, stop, and restart Tomcat by right-clicking on Tomcat's icon:

Configuring the server

You are now ready to start using Eclipse with Tomcat to develop servlets and JSPs. Nevertheless, before implementing your first servlet, let's take a look at how servlets are executed by servlet containers.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset