1 Reply Latest reply on Feb 5, 2012 2:48 PM by alan shields

    Application configuration

    alan shields Newbie

      Apologies in advance, I feel this stuff should be pretty basic but I'm no closer to an answer after several hours of searching so can somebody please give me some pointers to the bits of documentation that I've missed...

       

      I'm looking for a way to configure my application. I have an application ejb jar + library jars which I don't want to have to change between deployments (so no configuration files or resource ref entries inside them) placed inside an exploded ear directory that I can change. I require multiple of these ear's deployed to the same server with different configurations (but the same jars) so I need to find some way of determining configuration information specific to the ear. This would be on AS 7.

       

      I'm currently thinking of any of the following options but I can't find any way to implement any of them or even which ones are possible. I've underlined the areas that I'm having trouble with.

       

      1) some equivalent to resource ref defined in the ear to specify the database/directory whatever to get the config from

       

      2) read the name of the ear deployment from within the application then look up the appropriate config from a hard coded "configuration datasource"

       

      3) read a configuration file that's placed in the ear (I have tried this using getResourceAsStream but there seems to be some detail that I'm missing)

       

      Or is there something else that I haven't thought of?

       

      Thanks

       

      Alan

        • 1. Re: Application configuration
          alan shields Newbie

          Update

           

          I have found a way to read the name of the ear deployment here

           

          https://community.jboss.org/message/529950

           

          As described it doesn't work on jboss 7 (or at least in my situation), you just need to start off by obtaining the resource from the class loader of the current class rather than the context class loader.

           

          eg:

           

                    private String getEarName() {

                               URL url = getClass().getResource("");

                               Pattern p = Pattern.compile("(?i)/([^\\\\/:\\*\\?<>\\|]+)\\.ear/");

                               Matcher m = p.matcher(url.getPath());

                               if (m.find()) {

                               return m.group(1) + "/";

                               } else {

                               return "";

                               }

                    }

           

          Cheers

          Alan