4 Replies Latest reply on Mar 29, 2011 9:14 AM by komyg

    Accessing configuration files in JBoss 5.1

    komyg

      Hi, I am updating a Web Service server from JBoss 4.2.2 to JBoss 5.1, however when I began to use JBoss 5.1 I've got an error saying that one of my properties files could not be loaded.

       

      I have put this file in the following path: C:\Servers\jboss-5.1.0.GA\server\default\conf

       

      And I am using the code below to get its path:

       

      {code}

      String path;

       

      path = System.getProperty("catalina.base");

      path += System.getProperty("file.separator");

      path += "conf";

      path += System.getProperty("file.separator");

      {code} 

      As far as I know this code worked fine in JBoss 4.2.2, however in JBoss 5.1 the property "catalina.base" does not exists anymore (I believe that the getProperty method is returning null instead of the catalina.base actual value).

       

      Therefore I would like to know if there is any other property that returns the JBoss server folder or if there is a better way to access properties files inside JBoss 5.1.

       

      Thanks,

      Komyg

        • 1. Accessing configuration files in JBoss 5.1
          peterj

          The jboss.server.config.url property will give you the conf directory as a URL (file:///c:/Servers/jboss-5.1.0.GA/server/default/conf).

           

          Alternately, the conf directory is in the classpath, so you could use ClassLoader.getResource() or getResourceAsStream to load it also.

          • 2. Accessing configuration files in JBoss 5.1
            komyg

            Hi, thank you for your answer.

             

            I have used the jboss.server.conf property and it has returned me this: "file:/C:/Servers/jboss-5.1.0.GA/server/default/conf/", just as you said it would.

             

            However, since I am opening a properties file using the code below, I am getting a FileNotFoundException because of the "file:/" at the beginning of the property string.

             

            propertiesFile = new FileInputStream(path);

            properties.load(propertiesFile);

             

            Is there a way to retrieve this property without the "file:/", or is it better just trim the resulting String after it?

             

            Thanks,

            Felipe

            • 3. Accessing configuration files in JBoss 5.1
              peterj

              Try this:

               

              propertiesFile = new FileInputStream(new File(new URI(path)));

              1 of 1 people found this helpful
              • 4. Accessing configuration files in JBoss 5.1
                komyg

                Hi,

                 

                I've done as you suggested and everything worked fine.

                 

                Once again thank you for your help!

                 

                Felipe