5 Replies Latest reply on Jul 17, 2002 12:12 PM by sgturner

    The proper way to deploy a web app (war)

    ikant

      I know I'm not the only one to have this problem because I've seen at least half a dozen posts on this exact problem and it appears that the problem is that I was jaring the war improperly and other app servers (JRun and tomcat) were covering my error. Jboss will keep you honest. Here is how to properly archive a web app with the Sun jar tool:

      imagine I am creating a web app called exampleapp. I start by creating a directory called exampleapp. Inside it I create a index.html file and possible other html files and JSPs. exampleapp must also contain at least a directory called WEB-INF (case sensitive) with a web.xml configuration file inside of it (this should be familiar to everyone and in case it's not there is tons of online tutorials and books that teach how to use web.xml). 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:

      /home/projects/exampleapp <--top-most directory
      /home/projects/exampleapp/index.html
      /home/projects/exampleapp/WEB-INF <--directory
      /home/projects/exampleapp/WEB-INF/web.xml
      /home/projects/exampleapp/WEB-INF/classes <-- servlets and helper classes
      /home/projects/exampleapp/WEB-INF/lib <-- jars

      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. example:

      cd /home/projects/exampleapp
      jar -cvf exampleapp.war .

      This archives the war like so:

      /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

      Now that you have your exampleapp.war file copy it to:

      $JBOSS_HOME\server\default\deploy

      and Jboss should hot deploy the war, assuming it's running.

      Then you go to your favorite web browser and type:

      http://localhost:8080/exampleapp

      and it should display your index.html page or whatever you configured you web.xml file to show as it's welcome page.

      I hope this is helpful.

      -cheers