2 Replies Latest reply on Apr 30, 2003 9:55 AM by Adrian Brock

    ServletContext.getRealPath() does not work in JBOSS 3.2/Tomc

    jodybrownell1 Newbie

      Hello all,

      I have written an application listener to listen the contextInitialized event. At which time I am attempting to find the absolute file path of my
      application context via the following call ...

      String realPath = contextEvent.getServletContext().getRealPath("/");

      The value returned is always null. If I run this same code in tomcat 4.1.24 from jakarta (with no jboss) ... all is well. The path is resolved appropriately.

      Any thoughts? Does anyone know of a work around, or am I missing something obvious ....

      thanks in advance.

        • 1. Re: ServletContext.getRealPath() does not work in JBOSS 3.2/
          Jon Barnett Master

          When the servlet container cannot determine a valid file path for the method, such as when the web application is on a remote file system not accesible locally, in an archive or in a database, it will return null. So if your web application is still in a war, you will probably get this problem. In a standalone Tomcat, it normally unpacks the war so you can manifest a file path. Not so with the integrated Tomcat.

          Short version - you have no absolute file path when the application files do not manifest themselves in a real, physical way. Which is fine with the spec.

          I know that doesn't help much. You could try using properties already set but I'm not sure what you are after - for example you could read the jboss.server.home.dir. Or you can set properties in your web.xml for servlet initialisation. The only problem is the dependency inherent in this.

          • 2. Re: ServletContext.getRealPath() does not work in JBOSS 3.2/
            Adrian Brock Master

            Get real path only works with unpacked deployments.
            It is part of the servlet spec.

            You need to deploy your application using a directory
            structure that looks like a war file.