Skip to Main Content
Eclipse Cookbook
book

Eclipse Cookbook

by Steve Holzner
June 2004
Beginner to intermediate content levelBeginner to intermediate
364 pages
7h 38m
English
O'Reilly Media, Inc.
Content preview from Eclipse Cookbook

11.11. Creating WAR Files

Problem

You want to create a deployment file for a web application.

Solution

Compress the web application into a .war file, which is the kind of file you use to deploy web applications. You can create .war files from Eclipse using Ant.

Discussion

To get a look at how to deploy web apps using Eclipse, we’ll deploy the sample servlet in Example 11-8 for a project named DeployApp, which can be found at this book’s O’Reilly site. After compressing an application into a .war file, you can drop the .war file into the Tomcat webapps directory. Tomcat then expands and installs it when you restart Tomcat, which deploys the application.

Creating an application to deploy

To make it easier to create the .war file, give this project its own folder in the webapps directory (i.e., webapps\DeployApp). Don’t forget to add a WEB-INF directory with the subdirectories classes and lib, and make the classes folder the output folder for the project. Then enter the code in Example 11-8 to DeployClass.java.

Example 11-8. A servlet to deploy

package org.cookbook.ch11; import javax.servlet.http.HttpServlet; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class DeployClass extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.setContentType("text/html"); PrintWriter out = response.getWriter( ); out.println("<HTML>"); out.println("<HEAD>"); out.println("<TITLE>"); out.println("Deploying ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Eclipse

Eclipse

Steve Holzner
Official Eclipse 3.0 FAQs

Official Eclipse 3.0 FAQs

John Arthorne, Chris Laffra

Publisher Resources

Supplemental ContentCatalog PageErrata