(source: http://oak.cs.ucla.edu/cs144/projects/tomcat/)
Now that we understand the basic structure of a WAR file, we will be creating a very simple WAR file, called simple.war, that just contains a static "hello, world" type HTML page and the basic web.xml file. Here is a step-by-step instruction on how you can create a .war file:
Create a temporary folder to place all files that should go into the .war file. Make it as your current directory by "cd" into the directory.
Create a file named hello.html in your temporary directory with the following content.
<html>
<head><title>Hello World</title></head>
<body><h1>Hello World</h1></body>
</html>
Create a WEB-INF folder and create the deployment descriptor file web.xml in it with the following content.
<web-app id="simple" version="2.4">
<welcome-file-list>
<welcome-file>hello.html</welcome-file>
</welcome-file-list>
</web-app>
This descriptor file will make the hello.html page as the "default page" that your application returns.Since you are not including any servlet classes in the WAR file yet, you can skip steps 4 and 5 below and move directly to step 6.
Build your servlet classes. Create a WEB-INF/classes folder and copy your servlet classes into it.
Create a WEB-INF/lib folder and place all JAR library files that your servlet code depends on. After these steps, the layout of your temporary folder may look like the following, for example:
simple_temp
|
+- hello.html
|
+- WEB-INF
+- web.xml
|
+- lib
| +- core-library.jar
|
+- classes
+- edu
+- ucla
+- hello.class
At the root of your temporary folder, use the jar command to create your WAR file. For example:
jar cfM simple.war *
Follow the above instructions to build your "hello, world" page and web.xml as simple.war file and deploy it by placing the war file into the $CATALINA_BASE/webapps directory of your Tomcat server. Once deployed, point your browser to http://localhost:1448/simple. You should see the "Hello World" HTML page you specified as the welcome-file.
没有评论:
发表评论