4 Replies Latest reply on May 2, 2006 5:21 AM by navalonna

    Getting a relative path

    jaleyba

      Hi

      I did a MBean service that will start an ActiveMQ broker and it needs to read broker config from a file.

      For obvious reasons I want to have broker config file in JBoss conf directory, then my question is: how could I refer to JBoss relative path inside my service ?


      My code is:

      
       private void createNetwork() {
       log.info("BROKER SERVICE: trying to crete broker");
      
       try {
       URI brokerURI = new URI("xbean:file:/home/jcm/jboss-4.0.3SP1/server/default/conf/activemq.xml");
       service = BrokerFactory.createBroker(brokerURI);
       if (service != null) {
       service.start();
       }
       } catch (Exception e) {
       log.error("BROKER SERVICE: createNetwork Exception: " + e.getMessage());
       e.printStackTrace();
       }
       }
      
      



      I need to change xbean:file ..... to a relative path.


      Thanks in advance

      J



        • 1. Re: Getting a relative path
          jaleyba

          Please, could somebody give me a clue in this matter ?


          Thanks in advance

          J

          • 2. Re: Getting a relative path
            anders.hedstrom

            I guess you could use this:

            System.getProperty("jboss.server.config.url");


            or

            org.jboss.system.server.ServerConfigLocator.locate().getServerConfigURL();


            • 3. Re: Getting a relative path
              jaleyba

               

              "anders.hedstrom" wrote:
              I guess you could use this:

              System.getProperty("jboss.server.config.url");


              or

              org.jboss.system.server.ServerConfigLocator.locate().getServerConfigURL();


              Thanks !!!

              J



              • 4. Re: Getting a relative path
                navalonna

                I think you have a better solution.

                As conf directory of JBoss is in the application classpath, you can try to get your configuration file by getting it from the classpath.

                Classloader cl = Thread.currentThread().getContextClassLoader();
                InputStream is = cl.getResourceAsStream("your file");

                After that you have a stream for your file and you'll be able to read it.

                And that's all...