Friday, February 27, 2009

How to create a WAR file

How to create a WAR file - జస్వంత్ reddy

Here's how to compress a 'pets' web application into a "Web Archive" file named pets.war so that you can easily transport it to another server.

  • Open a command prompt and cd to
    \webapps\pets
  • Use the java archive command 'jar' to bundle up your application
    jar -cvf pets.war *
    In English, "compress everything in this directory into a file named pets.war"
    (c=create, v=verbose, f=file)

Now you can copy pets.war to any the webapps directory on a new Tomcat Server. When you save the file to a new server BE SURE not to save it as a ZIP file, choose "all files". If Tomcat is running on the new server the war file will be automatically installed as soon as you save it. If not, start up Tomcat on the new server to install the application after you have saved it. Do NOT attempt to unzip the war file or do any installation yourself. Tomcat will do everything for you!

When the server is restarted it will automatically uncompress the files and recreate a web application named 'pets'. (Do NOT attempt to unzip the war file yourself, let Tomcat take care of all that.)