How to Run a War File?


This question has been asked many times, and I figured it's worth repeating. The Simple answer:

1. Start the web server;

2. Deploy the war file to the web server;

3. Visit JSP pages or servlets in the browser.

 In more details:

1.  It is not possible to run a war file outside of a container.

A war file contains JSP pages, Servlet classes, static html files, and other java classes and resources.  It has to live inside of a container provided by application/web servers, just as applets are managed by a browser.  For example, you can download and install Glassfish, Tomcat, or Jboss

Start the web/application server.  Start the browser and visit http://localhost:8080 to confirm the server is running.  Your server may use a different web server port.  If you are not sure, try 8080 first.

2.  Copy the war file (say, helloworld.war) to the autodeploy directory of the application/web server.

It's so called auto-deploy or hot-deploy.  If you can't find such a directory in your server, look again.  If it's really not there, stop using this server immediately.  Althoug auto-deploy is not required by J2EE standards, virtually all servers support this.  Why choose an inferior one when you have so many choices?  See how easy it is to deploy a war file to Glassfish.

3.  In the browser visit http://localhost:8080/helloworld/

This is the root of your helloworld web application.  You may see errors in the browser if helloworld.war doesn't have welcome page (usually index.html, index.jsp, index.htm), and the server has disabled directory listing.

For individual JSP pages, you can access  http://localhost:8080/helloworld/say.jsp, assuming say.jsp is packaged directly inside the war file (that is, not under any subdirectory in the war file).

For individual Servlets, you can visit http://localhost:8080/helloworld/hello, assuming you have configured such a servlet-mapping for the url-pattern (/hello) and this servlet.  Usually you have to map the Servlet to a url-pattern in web.xml, and when you visit this url, the Servlet will be invoked.

technorati tags:

Comments:

Good

Posted by guest on May 01, 2008 at 12:34 AM EDT #

dfdf

Posted by guest on October 14, 2008 at 08:33 PM EDT #

thanks,,,, u save my career.....:P

Posted by Abdullah on January 10, 2009 at 08:16 PM EST #

really this post is very use full
...
I was been searching this for hours

Thanks

Posted by Yoges on January 22, 2009 at 10:14 PM EST #

Thank your very much this article. :)

Posted by scornik on February 21, 2009 at 03:49 PM EST #

Really, you're a great guy. You really helped me out in this thing.

Thanks

Posted by Mohamed K. Ismail on July 03, 2010 at 12:25 PM EDT #

interesting article

Posted by guest on July 10, 2011 at 03:19 PM EDT #

i cant start my server..it says 404 not found..what to do??

Posted by guest on December 29, 2011 at 02:47 AM EST #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Cheng Fang

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today