4 Replies Latest reply on May 23, 2006 1:05 PM by Peter Johnson

    property file outside jar

    Jo W Newbie


      I want to locate my property files outside the jar.
      Can I confgure JBOSS to specify the location of these property files?
      What is required in my code (Java), is it enough to provide the name of the property file and because of the configuration on the JBOSS server the file is found? Like:

      String filePath = "myprops.properties";
      Properties.load(new FileInputStream(filePath));

      can someone please help me?

        • 1. Re: property file outside jar
          Jo W Newbie

          Is there no expert who can help me or provide me a link where I can find some information?

          • 2. Re: property file outside jar
            Peter Johnson Master

            The following should work, assuming that your placed the properties file in the temp directory:

            Properties.load(new FileInputStream("/temp/myprops.properties");

            Or, let's say that you wanted to place the properties file into the JBoss server's data directory, then you could do:

            String dir = System.getProperties("jboss.server.data.dir");
            Properties.load(new FileInputStream(dir + "/myprops.properties");

            There are several other system properties that describe other locations within JBoss.

            • 3. Re: property file outside jar
              Jo W Newbie

              Thanks for the reply.

              In fact this is the problem I want to avoid.
              In case I put the location hard coded and the location of the property files changes, I have to do a code change.

              So I just want to have the property file name in the code (e.g. "appspec.properties") and make sure this property file is retreived.
              In this case, what do I have to configure to make sure the property file is searched in the correct location?

              • 4. Re: property file outside jar
                Peter Johnson Master

                An option that will tell the application where to look for the properties file because you want to hide it in a different location each time you run? How about specifying your own system property which defines the directory where the file is located.

                Personally, I would use a combination of my own system property along with the JBoss data directory property. If my system property is set, I would look there, if not then I would look in the data directory, and if not there, in no directory, which equates to the current working directory, which would be the JBoss bin directory. If I planned to run my application in app servers other than JBoss, I would add some of their system properties to my list of places to look.