1 2 3 Previous Next 30 Replies Latest reply on Dec 21, 2007 11:28 AM by Peter Johnson

    Unwaring web app - leaves some files in the war

    Dmitry Sklyut Newbie

      Hi,

      I am seeing a strange problem with the JBoss3.2_Tomcat4.1.24 bundle.

      I have a war web app, with the following structure:
      pages/
      web-inf/
      web-inf/classes/
      web-inf/classes/com/blah/blah
      web-inf/classes/config/
      web-inf/classes/prop.properties
      web-inf/classes/properties/
      web-inf/lib/

      Now, when that war is placed in the deploy directory it is getting delpoyed just fine. I am able to hit the jsps and the servlets. The problem is that prop.properties file and the properties folder never get extracted from the war to the tomcat area.

      The code that is looking for the prop.properties file is doing it this way:
      URL url = this.getClass().getClassLoader().getResource();

      With JBoss 3.2 + Tomcat 4.1.24 combo that url is null.

      With a plain vanila Tomcat 4.1.24 everything works just great. The whole war archive is exploaded into the work directory and prop.properties is found.

      I am puzzled by this. Did anyone else experienced that type of a problem? What am I missing?

      Thanks

      Dmitry

        • 1. Re: Unwaring web app - leaves some files in the war
          Eric M. Baggaley Newbie

          Hello,

          I am having the same problem with files in a war not being extracted. My war resides in an ear so I cannot just expand the files into a directory. I never had this problem on Windows, but as soon as I moved to Red Hat Linux I started to experience this problem. Did you ever find a resolution for this problem?

          • 2. Re: Unwaring web app - leaves some files in the war
            J B Novice

            Hi Folks,
            Im using the latest JBoss AS 5.0 beta2 and experiencing something similar to the above.

            I have a war file that looks like this
            myapp/conf/config.properties
            myapp/WEB-INF/ etc etc


            Ok now im a bit confused about what the "tmp" directory and the "work" directory do and their relationship if any, i havent see any docs on it and would appreciate any links if possible.(I do need to read up on this but ill ask anyways )

            Now the problem Im having is this, the war is exploded fine under the tmp directory but in "work" directory the .properties file is not there.

            i have a third party library which looks for the properties file under conf/config.properties, but if doesnt find it because there the class loader which loads the libs is loading the classes out of the "work" directory and not the tmp directory.

            So Im confused, which one is the correct exploded directory?? tmp or work and if its "work" which it seems to be because the classloader url is coming from the work directory, why isnt the .properties file exploded in there also??

            Cheers,
            LL


            • 3. Re: Unwaring web app - leaves some files in the war
              Peter Johnson Master

              The tmp directory is used to explode war/ear/sar/etc files. The work directory is used by Tomcat to compile JSPs.

              If you are loading a properties file using a directory location (as opposed to getting it from the classpath), you are better off deploying an exploded directory.

              • 4. Re: Unwaring web app - leaves some files in the war
                J B Novice

                Its a third party lib that i use that loads the resource file so i cant change how this works.It does this by getting hold of the class and then class.getResourceAs().

                As a work around for the moment i have copied the properties file into the "work directory" but this would not be an ideal solution for me.

                The war file is also part of an ear file so deploying an already exploded directory is not an option!!


                • 5. Re: Unwaring web app - leaves some files in the war
                  Peter Johnson Master

                  You could explode the existing ear and war files.

                  • 6. Re: Unwaring web app - leaves some files in the war
                    J B Novice

                    will try it tomorrow and will let you know how i get on!!

                    Cheers Peter,
                    LL

                    • 7. Re: Unwaring web app - leaves some files in the war
                      J B Novice

                      Ok i exploded the war file as a directory in the deploy directory and still i get the same problem. Makes no difference, the classloader loads the classes from the libraries inside the work directory so when class.getResource() gets called it returns a URL as to where the class file is located and from here it works its way up the URL dir structure to find the properties file but it aint there because the URL points to the work directory and in this directory the properties file aint there!!

                      Is this a bug or known limitation??




                      • 8. Re: Unwaring web app - leaves some files in the war
                        Peter Johnson Master

                        I am assuming that you also deleted the work and tmp directories, and restarted the server, when you exploded the war?

                        Looks like I will have to try this myself to see what is going on. Won't get to that until Monday, I'll post my results.

                        • 9. Re: Unwaring web app - leaves some files in the war
                          J B Novice

                          I did delete the sub dir in the work but not in the tmp!! will delete them and get back to you!!

                          • 10. Re: Unwaring web app - leaves some files in the war
                            J B Novice

                            Ok I deleted the sub-dir for my war in both the tmp and work directories. I have my war file exploded in a directory in the deploy directory but still no joy.



                            • 11. Re: Unwaring web app - leaves some files in the war
                              Peter Johnson Master

                              LL, I am trying to replicate the problem, but I have a few questions.

                              1) Originally, you stated that the your WAR contained:
                              myapp/conf/config.properties
                              myapp/WEB-INF/ etc etc

                              Did you really mean the the WAR is as follows:

                              myapp.war
                              + conf
                               + config.properties
                              + WEB-INF


                              In other words, within your WAR there is not a base directory named myapp and that instead both conf and WEB-INF are base directories.

                              2) You stated that the code "class.getResourceAs()" is used to access the properties file. My understanding of getResourceAsStream (which is what I think you meant) is that the file is loaded using the class loader, and therefore the properties file would have to be located at WEB-INF/classes/config.properties (or within a jar in WEB-INF/lib).

                              I assume that in the WAR file there is a conf base directory and the properties file is located in that directory. Could you post the exact code used to access the properties file, including the code that obtained the 'class' variable.

                              3) I noticed you are using 5.0 beta2. Have you tried your app in 4.2.x? Does it work there? The reason I ask is because the deployer in beta2 is broken in so many ways, in which case you might have been lucky enough to find another way that it is broken.

                              • 12. Re: Unwaring web app - leaves some files in the war
                                J B Novice

                                 


                                Did you really mean the the WAR is as follows:


                                First off I had everything packed in the war, then i did like you suggested and exploded the WAR in a directory so it looked like
                                deploy
                                +myapp.war
                                 +conf
                                 +config.properties
                                +WEB-INF
                                



                                In other words, within your WAR there is not a base directory named myapp and that instead both conf and WEB-INF are base directories.

                                When you say this i assume that you think i exploded the war into the deploy directory without a base directory.(I assume thats what you mean).No it does have a base directory

                                deploy
                                +myapp.war (The dir is called myapp.war)

                                and inside myapp.war is the sub-directories.

                                Heres the code, sorry it uses Class.getResource and not class.getResourceAS


                                static
                                 {
                                 try
                                 {
                                 Class class1 = (new ProjectRootClass()).getClass();
                                 URL url = class1.getResource("ProjectRootClass.class");
                                 String s = url.toString();
                                 System.out.println((new StringBuilder()).append("ProjectRootClass: Probe URL is ").append(s).toString());
                                 theProjectRoot = s.substring(s.indexOf("file:") + 5, s.lastIndexOf("/WEB-INF/"));
                                 System.out.println((new StringBuilder()).append("ProjectRootClass: The project root was detected at ").append(theProjectRoot).toString());
                                 }
                                 catch(Throwable throwable)
                                 {
                                 System.err.println("ProjectRootClass: Initialisation failed");
                                 throwable.printStackTrace();
                                 theProjectRoot = "";
                                 }
                                 }


                                The code works out where the root directory of the war file is and from here uses the root to find the config.properties but because it loads the class from the work directory and not the tmp directory it wont find the properties file.


                                I noticed you are using 5.0 beta2. Have you tried your app in 4.2.x? Does it work there? The reason I ask is because the deployer in beta2 is broken in so many ways, in which case you might have been lucky enough to find another way that it is broken.


                                I will download 4.2.x and will post my findings later today.


                                • 13. Re: Unwaring web app - leaves some files in the war
                                  J B Novice

                                  Ok using 4.2.2.GA

                                  I see the difference now. In 5.0 version the whole lib directories are copied over into the work directory, this is not the case in 4.2.2GA,

                                  My dir structure in the work directory looks like this
                                  5.0 version


                                  myapp
                                  +org
                                  +WEB-INF
                                  + lib
                                  tldCache.ser


                                  In the 4.2.2GA i have no WEB_INF dir, just the org directory

                                  myapp
                                  +org
                                  tldCache.ser



                                  So if going on how the 4.2.2GA works then i shouldnt have any WEB_INF directory in my work directory which i do!!!


                                  • 14. Re: Unwaring web app - leaves some files in the war
                                    J B Novice

                                    Sorry in that last post it might look a bit confusing, the indentation didnt come through but the lib directory is under the web-inf directory.

                                    Just in case any confusion!! ;)

                                    1 2 3 Previous Next