4 Replies Latest reply on Dec 9, 2004 8:11 AM by sylobsa

    Static resource location

      Hi all,

      I'd like to get the URL of a properties file from within a class located in the EJB tiers (in MyEjb.jar).

      This properties file is located in MyModule.war J2EE module, included in MyApp.ear.
      MyEjb.jar is also included in MyApp.ear.
      Is there a way to find the properties file and get it's absolute path so my business class can open it ?

      Regards

        • 1. Re: Static resource location
          frito

          You don't need an absolute path.
          If the properties file is located in your archive, it is in your apps class path, too.
          Use the ContextClassLoader for loading it.

          • 2. Re: Static resource location

            Thank for your response.
            I don't need absolute path and must use the ContextClassLoader. But can you give me an example on how to use it and get my properties file ?

            Regards


            • 3. Re: Static resource location
              frito

              Let's say your property file "myProp.properties" is located at top level in one of your JARs:

              InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("myProp.properties");

              • 4. Re: Static resource location


                Doesn't work for me.
                Here is my configuration :

                MyApp.ear
                static.war
                MyWeb.war
                MyEJB.jar

                The properties file is in the static.war archive.
                The path is : /dir1/dir2/MyFile.properties

                The class needing this properties file is located in the MyEJB.jar archive.

                I tried :

                InputStream is = Thread.currentThread()
                .getContextClassLoader()
                .getResourceAsStream(f);

                with :
                f="/static/dir1/dir2/MyFile.properties"
                f="MyFile.properties"
                f="/dir1/dir2/MyFile.properties"

                The "is" input stream is always null.