6 Replies Latest reply on May 22, 2018 11:52 AM by l33thaxor

    Reading a configuration file

    aecordoba

      Hello, there!

      I'm writing a web application, and planning to deploy it on JBoss AS 7.1.

      My application need to read some configuration properties from a file.

      Where should I put this configurations file within JBoss home directory?

      I'm using Maven and put the configuration file on "src/main/resources". So, the file is placed in "JBOSS_HOME]/standalone/deployments/[MY_APPLICATION].war/WEB-INF/classes/" when I run the application, but it cannot get the configuration properties.

      The application can only read the configuration properties if I put the file in "JBOSS_HOME]/bin" directory. Is this the right place?

       

      Thank you, in advance.

       

      --

      [Adrián E. Córdoba]

        • 1. Re: Reading a configuration file
          shakirpm4u

          Ideally, You should be able to put anywhere in the server. Only thing is you have to configure the proper location on your project.

           

          Properties prop = new Properties();
          InputStream in = getClass().getResourceAsStream("foo.properties");
          prop
          .load(in);
          in
          .close();



          Or if you plan to read from Classpath, Put it in WEB-INFclasses folder. Thats the right place. I dont think bin is correct location.

           

          Thanks

          • 2. Re: Reading a configuration file
            wdfink

            Reading properties from a file is not a portable way and violate the spec (you should not use java.io.*).

            You might use the WEB-INF/classes folder as shakirpm4u describe other option in AS7 is to set it as system-property within the configuration.

            • 3. Re: Reading a configuration file
              aecordoba

              Thank you, Shakir.

              Thank you, Wolf-Dieter.

              • 4. Re: Reading a configuration file
                ryanaguilar

                Nice very helpful

                • 5. Re: Reading a configuration file
                  celle2006

                  Hi Adrian,

                   

                  i put my properties files in a custom module. So i have to reference it in the MANTIFEST.MF file with the Dependencies attribute. When i want to read the file i have to load it like this:

                   

                            Properties props = new Properties();

                            props.load(this.getClass().getClassLoader().getResourceAsStream("foo.properties"));

                   

                  The advantage to put properties file in modules section. You do not have to change the properties everytime you deploy to your productiv system, if you have differences between developing and productiv systems.

                   

                  Kind regards

                   

                  Marcel

                  • 6. Re: Reading a configuration file
                    l33thaxor

                    Using java.io.* gave me huge performance issues. I am hoping to find a solution where I don't have performance issues