Thư viện tri thức trực tuyến
Kho tài liệu với 50,000+ tài liệu học thuật
© 2023 Siêu thị PDF - Kho tài liệu học thuật hàng đầu Việt Nam

ECLIPSE WEB TOOLS PLATFORM developing java web applications PHẦN 2 doc
Nội dung xem thử
Mô tả chi tiết
Iteration 1: J2EE Web Applications 49
3. Click the Next button to display the Tomcat Server page. Click the Browse
button to select the directory where you installed Tomcat (see the Getting
Tomcat sidebar), for example,
E:\jakarta-tomcat-5.0.28
The Tomcat installation directory field should now show the selected
directory (see Figure 3.4).
Figure 3.4 Tomcat Server
4. The JRE field is initialized to the Workbench default JRE, which is the JVM
you used to launch Eclipse.
JDK Required for JSP Development
Part of the server runtime environment setup process involves specifying the JRE to
use for launching Tomcat. Be sure to specify a full JDK instead of just a JRE because
you’ll be doing JSP development. If you do not currently have a JDK defined to Eclipse,
add the one you previously installed (see the Getting a JDK sidebar). JSP development
requires a Java compiler, which is included in the JDK but not the JRE. JSP compilation
will fail if you specify a JRE. Note that you can precompile your JSPs in order to use a
JRE in your production server environment.
Click the Installed JREs button to open the Installed JREs wizard. This wizard
lets you define additional JREs to Eclipse. Click the Add button and select
the directory where you installed the JDK (see the Getting a JDK sidebar),
for example,
E:\ibm-java2-142
The JDK is added to the Installed JREs page. Select its checkbox to make it
the default JRE (see Figure 3.5), and click the OK button to return to the
Tomcat Server page.
50 CHAPTER 3 • Quick Tour
Figure 3.5 Installed JREs
5. Select the JDK from the drop-down list of the JRE field (see Figure 3.4).
When WTP launches Tomcat later, it will use the specified JDK. Click the
Finish button to complete the definition.
Tomcat is now listed on the Installed Server Runtime Environments page (see
Figure 3.6). You have now extended Eclipse with a J2EE servlet container
and are ready to create your first Java Web application development
project.
Create a Dynamic Web Project
We assume you are familiar with the Eclipse concepts of workspace, project, and
builder. Recall that an Eclipse workspace contains a set of projects. You typically
put projects that are related to each other in the same workspace. For example, in
J2EE development, you would put related Web, EJB, and utility projects in the
same workspace. Each project has a set of builders associated with it. Builders are
what give the project its intelligence. Builders know how to process the artifacts in
a project. The most common example of a builder is the Eclipse incremental Java
compiler, which knows how to compile your Java source files into class files.
WTP provides builders for Java Web applications. These builders know, for
example, how to package the artifacts in J2EE modules so that they can be
deployed to J2EE application servers.
In general, a J2EE application will contain several modules. For example, you
might want to use a Web module for the presentation logic and an EJB module
for the business logic. Here you’ll just develop a Web module. Do the following to
add a Web module to your workspace:
Iteration 1: J2EE Web Applications 51
Figure 3.6 Installed Server Runtime Environments with Tomcat Added
1. To begin development, create a new dynamic Web project by invoking the
File New Project menu command to open the New Project wizard.
Select Web Dynamic Web Project as the project type (see Figure 3.7).
52 CHAPTER 3 • Quick Tour
Figure 3.7 New Project
2. Click the Next button. The Dynamic Web Project page is displayed (see
Figure 3.8). Enter Web1 in the Project Name field. Note that Apache Tomcat
is selected as the Target Runtime since it is the only server runtime environment you have defined. The Configurations field lets you select a predefined
configuration of project facets. Leave the setting as <custom> for now. You
can also ignore the checkbox to add the Web module to an EAR project
since Tomcat is just a servlet container and doesn’t support EARs.
3. Click the Next button to advance to the Project Facets page (see Figure 3.9). A
facet is part of the runtime configuration of a project, such as the version of
Java or J2EE. Facets will be discussed in more detail in Chapter 6. For now,
simply accept the selections.
4. Click the Next button to advance to the Web Module page (see Figure 3.10).
You can change some of the project settings here. For example, the Context
Root of the Web application defaults to its project name, Web1. Accept the
defaults for now.
Iteration 1: J2EE Web Applications 53
Figure 3.8 Dynamic Web Project
Figure 3.9 Project Facets
54 CHAPTER 3 • Quick Tour
5. Click the Finish button to create the Web project. Since this is the first
time you have created a Web project, you are prompted to accept the
J2EE license from Sun (see Figure 3.11). WTP will next attempt to download the J2EE schemas from the Sun Web site, so you must accept the
license before WTP proceeds. Products built on top of WTP may have
obtained the right to redistribute the J2EE schemas, in which case you
won’t see this dialog.
6. Click the I Agree button to accept the license. Note that if you
do not accept the license, then WTP will be unable to validate the
J2EE XML artifacts, such as the deployment descriptors (e.g., web.xml),
you create.
WTP has a special J2EE perspective and will attempt to switch to
it when you create any J2EE project, such as a dynamic Web project
or an EJB project. One of the user interface design guidelines of Eclipse is
to not switch perspectives without asking the user if they want to.
You are therefore prompted to switch perspectives (see Figure 3.12).
Figure 3.10 Web Module
7. Click the Yes button to agree to the switch. The wizard opens the J2EE
perspective for you so you can see the logical structure of your modules.
The J2EE Project Explorer view (see Figure 3.13) now shows the project
structure after Web1 has been created. Note that the wizard created some
folders and files under the Web1 module. These items are defined by the
J2EE specification. For example, the WebContent folder is the root of the
Web application and is where the normal Web content, such as HTML
Iteration 1: J2EE Web Applications 55
Figure 3.12 Open Associated Perspective
Figure 3.11 License Agreement