UK Sales: 0800 035 6364 | sales@2020media.com | We'll Call You

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

 

2020Media is a leading provider of small business Wi-Fi hotspots. If you want to offer free Wi-Fi to your customers or users, our service could be exactly what you are looking for. Our Hotspots are managed in the cloud, ultra-reliable and give you loads of information about behaviour patterns of your users. Read More   Read more...
2020Media introduces Moodle Hosting - UK servers and UK Moodle experts setup your site ready to use. Read more...
Special Offer for Longer Registration Periods Register or renew a .com, .net or .org domain name for 5 years we'll include 1 year free*. Read more...
2020Media is now offering zero-click installation of the popular TYPO3 content management system. Read more...

Our blog is regularly updated with news, tips and industry opinion.

Clients

  • AggieWestons
  • baker-and-mckenzie
  • arts-council-england
  • Big Finish
  • barratt-developments-logo
  • City-of-Lincoln-council-logo
  • brora-logo
  • DenisMacShane
  • Construction-Industry-Council
  • colchester