1 2 3 Previous Next 34 Replies Latest reply on May 30, 2003 2:02 AM by droolinggeezer

    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

        • 1. Re: The proper way to deploy a web app (war)
          bleupen

          good post!

          for projects in development, it is most convenient to create a directory called "exampleapp.war" (or whatever your app is called) and point the JBoss deployer at the directory above it (e.g. "file://home/projects/").

          This will save you the trouble of jar'ing your application every time you make a change.

          b

          • 2. Re: The proper way to deploy a web app (war)
            geepe99

            Good post, thanks. I am a JBOSS newbie, moved from JRun recently. Don't we have the JRun equivalent of web server to app server connector here. ?
            Also, I get a 400 null error when I do the steps you mentioned.Any obvious mistakes.. ?

            Any help would be appreciated
            Thanks
            Ganesh

            • 3. Re: The proper way to deploy a web app (war)
              mlapolla

              Great post. I followed this and finally got it working.

              Q: Now that I have this working, my Apache 2.0 is not working. I have mapped, or tried to, Apache 2.0 to jboss-3.0.0_tomcat-4.0.3 by using mod-jk.dll, which I have working for tomcat-4.0.3 perfectly. To make this work, I put



              in tomcat4-service.xml. However, http://localhost/example/jsp/index.html

              which should now be working because

              http://localhost:8080/example/jsp/index.html

              works. But it is not.

              Thanks.


              • 4. Re: The proper way to deploy a web app (war)
                jasonbrome

                For those of you just getting into building Web applications - this is also a good time to start to learn about Ant. Ant ( http://jakarta.apache.org/ant ) is a Java-based build tool that will enable you to script the build process, including compilation and packaging, of your application.

                Recent versions have featured a task specifically for the purposes of building WAR files. The task is quite flexible, and enables you to build a WAR by referencing files within your existing project - i.e. you do not have to copy the files over into a structure representing the WAR file.

                Here's an example snippet that builds a WAR named mywebabb.war, including a dependent library, web.xml, web app related classes, jboss specific web deployment descriptor, tag library descriptions, jsps, and jpeg images.

                ...


                    
                        
                    
                    
                        
                    
                    
                        
                    

                    
                        
                    

                    
                        
                        
                    


                ...

                Good luck,

                Jason

                • 5. Re: The proper way to deploy a web app (war)
                  mladwig

                  Is there any reason that this formula can't be used to make the jboss example/template work? I'm struggling with that problem.

                  mike.

                  • 6. Re: The proper way to deploy a web app (war)
                    cnlzg

                    a ant profile:
                    <?xml version="1.0" encoding="UTF-8"?>
                    <!--
                    clean - Remove all generated files.
                    prepare - Set up build directory structure.
                    compile - Compile all needed java source
                    web-dist - package all needeb by web application
                    ejb-dist - package all needed by ejb application
                    all - Almost everything.
                    web-deploy - copy all needed to jetty
                    ejb-deploy - copy all needed to jboss
                    deploy - deploy all
                    -->






                    <!---->
























































                    • 7. Re: The proper way to deploy a web app (war)
                      erik777

                      What if you want to access your "application" from the root folder of your website, instead of from a subfolder? How can you do this with JBoss/Tomcat bundled.

                      I have halted progress on OpenStandards.net for two weeks in search of an answer to this question, but NO ONE will try to answer it. This is extremely frustrating.

                      Tomcat without JBoss allows you to do it in the server.xml using the context tag and the docBase property. It even gives an example with the ROOT application.

                      • 8. Re: The proper way to deploy a web app (war)
                        oz_ko

                        I've been trying to get JBoss to deploy an COMPLETELY UNPACKED standard ear with no success!

                        I can get an unpacked war to work correctly, but not the whole application - including unpacked ejb.jar and webapp.war

                        Can JBoss actually handle a completely unpacked application? If so what do you need to do? Unfortunately the books haven't been much help in this case either. Am I missing something?

                        Thanks,
                        Oz

                        • 9. Re: The proper way to deploy a web app (war)
                          davidjencks

                          jboss 3 + certainly can. Does your directory structure exactly match a jarred structure, with each "package name" like myapp.ear being a directory? Did you get META-INF, not meta-inf?

                          • 10. Re: The proper way to deploy a web app (war)
                            benw

                            erik777,

                            What do you mean root folder of your website? Can you be a little bit more specific? With JBoss/Tomcat bundled, you should still deploy your "application" in JBoss's deploy directory (e.g. jboss/server/default/deploy). You can deploy the "application" as a directory structure or as a packaged archive (war or ear archive).

                            Ben

                            • 11. Re: The proper way to deploy a web app (war)
                              erik777

                              What I mean is that you can have JSP pages in your web root (e.g., http://www.OpenStandards.net/index.jsp). With war deployment, regardless of whether or use a folder in JBoss deploy or a JAR archive, your JSP pages are effectively deployed in a subfolder from your web root (e.g. deploying testapp.war would result in http://www.OpenStandards.net/testapp/).

                              Tomcat allows you to configure a specific WAR as your root application. Search for "ROOT" in the server.xml that installs with Tomcat for an example. Tomcat goes even further by allowing you to JSP/servlet enable any folder in your file system.

                              However, JBoss bundled with Tomcat ignores the server.xml. So, the question is, how can you declare an application as a "root application" that will be accessed from the root folder of your website with JBoss bundled into Tomcat?

                              BTW, the reason OpenStandards.net is working now is because I am currently using JBoss 2.4 in production bundled with Tomcat 3. This version does not disable the server.xml, so I was able to use all of Tomcat's features. I need to upgrade to JBoss 3/Tomcat 4, though. I have halted adding any new features until this problem is resolved. Considering that the site serves those who support open standards and open source, this is not good.

                              Thanks,

                              Erik
                              OpenStandards.net

                              • 12. Re: The proper way to deploy a web app (war)

                                You can for jboss3 use a WEB-INF/jboss-web.xml with
                                the following content:

                                <?xml version="1.0"?>
                                <!DOCTYPE jboss-web>

                                <jboss-web>
                                <context-root>/</context-root>
                                </jboss-web>

                                Regards,
                                Adrian

                                • 13. Re: The proper way to deploy a web app (war)
                                  erik777

                                  Thank you. It worked.

                                  • 14. Re: The proper way to deploy a web app (war)
                                    aweissman

                                    I've had a lot of difficulty with this issue. I can create a .war directory and define it as the '/' by <context-root> entry in jboss-web.xml, but I can't get the server to recognize a '.war' directory nor a 'ROOT.war' directory as '/' automatically. Any ideas why?

                                    1 2 3 Previous Next