Skip to content

2020Media

Home Contact Us News Webmail
 

Newsflash

2020Media is offering full support for Joomla, Magento, SugarCRM on hosting packages
 
You are here: Home arrow Tools arrow Dynamic Content inc Java arrow Generating WAR Files
Generating WAR Files PDF Print E-mail

Generating WAR Files

WAR files (Web Application Archive) are used to deploy Java applications. They hold the static pages, classes, JSP files, property files and other configuration information.

Here is how to generate a WAR file with the Sun jar tool. (This is part of the standard Java development kit).

Imagine you are creating a project called exampleapp.

You would normally create a directory somewhere on your local computer called 'exampleapp', and within that you would create the files needed for the project.

The exampleapp directory must also contain at least a directory called WEB-INF (case sensitive) with a web.xml configuration file inside of it (If you are unfamilar with web.xml files, then you should look at this example and make any changes necessary).

Optionally, the WEB-INF directory may also contain a directory called classes that contains servlets and classes used by them or by JSPs and a directory called lib where you can store your JAR files used by the classes in your classes directory.

So on a unix system your file structure might look like this:

File / Directory Comment
/home/projects/exampleapp top-most directory for html pages, jsps, other directories for images etc
/home/projects/exampleapp/index.html Static pages
/home/projects/exampleapp/WEB-INF Directory (name is case sensitive)
/home/projects/exampleapp/WEB-INF/web.xml Configuration file
/home/projects/exampleapp/WEB-INF/classes Directory containing class files
/home/projects/exampleapp/WEB-INF/lib Directory containing 'jar' files

(On windows system structure will be exactly the same - but the file names will use the '\' character and may start with a drive letter.

Once you have prepared your files this way, you package them into a war file by navigating into the exampleapp directory and using the sun jar tool to archive the war.

cd /home/projects/exampleapp
(cd c:\home\projects\exampleapp)

jar -cvf exampleapp.war .

You can check the war file is correct by typing

jar -tvf exampleapp.war

and you should see lines ending

/index.html
/WEB-INF
/WEB-INF/web.xml
/WEB-INF/classes
/WEB-INF/lib

The incorrect way (and the way many of us have done it) would be to navigate to /home/projects/ and type:
jar -cvf exampleapp.war exampleapp

Which would create the incorrect structure of:

/exampleapp
/exampleapp/index.html
/exampleapp/WEB-INF
/exampleapp/WEB-INF/web.xml
/exampleapp/WEB-INF/classes
/exampleapp/WEB-INF/lib

 

 
< Prev   Next >
Advertisement

Domain Search

Preferred Extensions -
.com .co.uk
.net .org
.me .eu
Nominet Members
Nominet members since 1999
CentralNic Accredited Registrar
Accredited since 2001
Imperial Registrations Platinum Partner
ICANN Accredited
RIPE member
RIPE member since 2002
 
[+]
  • Narrow screen resolution
  • Wide screen resolution
  • Auto width resolution
  • Increase font size
  • Decrease font size
  • Default font size