Tải bản đầy đủ (.pdf) (32 trang)

Installing the Eclipse Web Tools Platform

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (1.22 MB, 32 trang )

Installing the Eclipse Web Tools
Platform
N
o longer is it acceptable to run through a long and cumbersome series of steps just to see if a
simple change worked. The modern way to create web applications is to embrace integrated devel-
opment environments (IDEs) and the benefits they offer. Two leading Java IDEs—Eclipse (http://
www.eclipse.org) and IntelliJ IDEA ( you to work quickly
and efficiently, avoiding painful and delayed deployment.
In this appendix, we will show you how to set up and configure Eclipse with its Web Tools Plat-
form (WTP). We are providing instructions for the Eclipse WTP because it is free and easily avail-
able. Both the Eclipse and IntelliJ IDEA IDEs are excellent, and there is no bias for one over the
other. We recommend that after you get started, you try them both to see which you prefer. It’s
worth the effort to find your favorite IDE—even if it costs money—if you make your living develop-
ing web applications.
So what is the Eclipse WTP, and what does it bring to the standard Eclipse IDE? To quote the
Eclipse WTP home page (
The Eclipse Web Tools Platform (WTP) Project provides APIs for J2EE and Web-centric appli-
cation development. It includes both source and graphical editors for a variety of languages,
wizards and built-in applications to simplify Web Service development, and tools and APIs to
support deploying, running, and testing apps.
In other words, it brings editors and wizards for common web application development tasks
into the Eclipse IDE. With the WTP, you’ll have editors for HTML, JSP, XML, and other files.
But most important is the fact that the WTP allows you to run a servlet container, such as
Tomcat, inside Eclipse. This means that you can deploy and debug web applications directly inside
your IDE with a single click. This also means that you don’t need to recompile and redeploy your
web application while developing. It’s now possible to make changes to your application, including
both JSP files and your Java classes, and see those changes reflected in your server live. This is a
huge time-saver, and the core reason why we are recommending that you use a modern IDE.
We are assuming you have some knowledge of Eclipse, or that you have used Java IDEs before.
What follows is not a generic Eclipse tutorial. For more information on Eclipse, we recommend
Eclipse in Action (Manning, 2003).


303
APPENDIX
9187appA.qxd 8/1/07 10:14 AM Page 303
Installing Tomcat
Even though the Eclipse WTP includes servlet container integration for many of the top containers,
it does not include an actual servlet container. You can choose from many excellent and mature
servlet containers, but we recommend the Tomcat server from the Apache Group. Tomcat is free
and open source, and the WTP integrates with it very well. Before you download and install the WTP,
take the time to download the latest version of Tomcat 5.5 from />You must use Tomcat 5.5.x or later to run the examples in this book, because we take advantage
of JSP 2.0 and Servlet 2.4 specifications. However, Spring MVC applications do not require a
Servlet 2.4-compliant container (but we do recommend using the latest versions and specifications,
if possible). Tomcat 5.5 requires Java 5 or later.
Follow these steps to download Tomcat:
1. Go to />2. Choose the latest version of the Core distribution. Select the zip or tar/gz download,
whichever one you prefer. Don’t download the Windows executable.

Note
Tomcat comes in a Windows installer download and a platform-independent download. We recommend
that you download the platform-independent version, even if you’re running on Windows. There’s really nothing to
install—it’s just a matter of configuring Tomcat in the Eclipse WTP—and this download allows you to extract
Tomcat wherever you want.
3. Extract the archive to a location on your drive. You’ll need to point to the directory contain-
ing the Tomcat distribution when configuring Tomcat in the WTP.
There is no configuration of Tomcat required, as the WTP will manage the server and your web
application.
Installing Eclipse
The current version of Eclipse is 3.2 and is part of the Callisto project. Once Eclipse is downloaded
and running, you can download and install the WTP through the built-in update manager. We’ll run
through all the steps required to get Eclipse and the WTP working, so that you can start creating
web applications with the Spring Framework and Spring MVC.

Do you already have an Eclipse installation? That’s not a problem, as you can point multiple
Eclipse installations to the same workspace. That way, you won’t interfere with your existing Eclipse
installation, and you’ll get the benefits of a simple, stand-alone web application development IDE.

Note
You must have a Java Development Kit (JDK), version 5 or greater, downloaded and installed before
attempting to run Eclipse.
Follow these steps to download and run Eclipse:
1. Go to This page will display the download for your
platform (Windows, Mac OSX, or Linux).
2. Choose a mirror close to you.
3. Download and unzip the file into an easy-to-remember directory.
APPENDIX

INSTALLING THE ECLIPSE WEB TOOLS PLATFORM304
9187appA.qxd 8/1/07 10:14 AM Page 304
APPENDIX

INSTALLING THE ECLIPSE WEB TOOLS PLATFORM 305
4. Browse to the directory you unzipped the file into and run the eclipse command
(eclipse.exe for the Windows platform).
5. Accept the default workspace location if you haven’t run Eclipse before. If you have used
Eclipse before, the suggested location will be your existing workspace. You can choose
another workspace location if you want to create a new one, but you can just reuse your
current one.

Note
If you’re already using Eclipse, any additional plugins you may have installed will not be available in
Eclipse 3.2, which means you will need to reinstall them.
Congratulations, you now have Eclipse installed and working, and are ready to install the WTP.

Installing WTP
The Eclipse WTP and other plugins that are part of the Callisto project can be downloaded and
installed from the Callisto update site via the built-in update manager. Here are the steps to install
the WTP:
1. Open the Eclipse update manager by selecting Help ➤ Software Updates ➤ Find and Install,
as shown in Figure A-1.
Figure A-1. Starting the software update process
9187appA.qxd 8/1/07 10:14 AM Page 305
2. The Install/Update screen will be displayed, as shown in Figure A-2. Select the second
option, “Search for new features to install,” and click Next.
Figure A-2. Choosing to search for new features
3. Click the check box next to Callisto Discovery Site to select it. Make sure it is the only site
selected, as shown as Figure A-3. Click Finish.
4. Select an update site close to your location from the Update Site Mirrors list, as shown in
Figure A-4. Click OK to continue.
APPENDIX

INSTALLING THE ECLIPSE WEB TOOLS PLATFORM306
9187appA.qxd 8/1/07 10:14 AM Page 306
Figure A-3. Selecting the Callisto Discovery Site
Figure A-4. Choosing an update site
APPENDIX

INSTALLING THE ECLIPSE WEB TOOLS PLATFORM 307
9187appA.qxd 8/1/07 10:14 AM Page 307
5. In the list of features to install, check the Web and J2EE Development option. You will get a
warning message saying dependencies are missing. Click the Select Required button to
resolve these, as shown in Figure A-5. Click Next.
Figure A-5. Choosing to download the WTP, as well as its dependencies
5. Select “I accept the terms in the license agreements” and click Next.

APPENDIX

INSTALLING THE ECLIPSE WEB TOOLS PLATFORM308
9187appA.qxd 8/1/07 10:14 AM Page 308
6. Accept the default location for installing the WTP (shown in Figure A-6) and its dependen-
cies by clicking Finish. The plugins will now be downloaded.
Figure A-6. Completing the WTP installation
APPENDIX

INSTALLING THE ECLIPSE WEB TOOLS PLATFORM 309
9187appA.qxd 8/1/07 10:14 AM Page 309
7. Surprisingly, some of the downloaded plugins may not be properly signed, as shown in
Figure A-7. Click Install or Install All to approve their installation.
Figure A-7. Details of a plugin that is not properly signed
8. After all plugins have been installed, click Yes to restart Eclipse with the WTP.
With the WTP installed, you’re ready to create a new web project.
Starting a New Web Project
The WTP includes a new project type, the Dynamic Web Project. This project type is what you’ll
use whenever you create a servlet-based (and thus Spring MVC) application. The Dynamic Web
Project type includes and integrates all of the helpful wizards and editors that are useful when
developing a web application. We will now show you how to create a new, blank Dynamic Web
Project.
APPENDIX

INSTALLING THE ECLIPSE WEB TOOLS PLATFORM310
9187appA.qxd 8/1/07 10:14 AM Page 310

Note
The following instructions are valid for at least Eclipse 3.2 and the WTP. Different versions of this product
might require different steps.

1. Select File ➤ New ➤ Project to start the New Project wizard.
2. Open the Web folder and choose Dynamic Web Project, as shown in Figure A-8. Then click
Next.
Figure A-8. Choosing to create a Dynamic Web Project
APPENDIX

INSTALLING THE ECLIPSE WEB TOOLS PLATFORM 311
9187appA.qxd 8/1/07 10:14 AM Page 311
3. Choose a meaningful name for the project. Figure A-9 shows an example. You next need to
configure a target runtime. This is the servlet container in which the application will run
during development. Click the New button to create a new server runtime.
Figure A-9. Setting up a Dynamic Web Project
APPENDIX

INSTALLING THE ECLIPSE WEB TOOLS PLATFORM312
9187appA.qxd 8/1/07 10:14 AM Page 312
4. Select your server runtime environment. For the examples in this book, we are using
Tomcat 5.5. Open the Apache folder and choose Apache Tomcat v5.5, as shown in
Figure A-10. Then click Next.
Figure A-10. Choosing Tomcat as the target runtime
APPENDIX

INSTALLING THE ECLIPSE WEB TOOLS PLATFORM 313
9187appA.qxd 8/1/07 10:14 AM Page 313
5. Now it’s time to point to the directory where you extracted the Tomcat download. Click the
Browse button and locate the Tomcat installation directory, as shown in Figure A-11. It’s a
good idea to double-check that you are using Java Development Kit (JDK) 5 for this web
project. You can use the New Server Runtime dialog box to choose JDK 5. Click the Finish
button.
Figure A-11. Specifying the Tomcat installation directory

APPENDIX

INSTALLING THE ECLIPSE WEB TOOLS PLATFORM314
9187appA.qxd 8/1/07 10:14 AM Page 314

×