1 Reply Latest reply on Jul 9, 2004 11:29 AM by Nicholas Whitehead

    Accessing resources from within a MBean

    adenied Newbie

      Hello,

      I've written a simple MBean and deployed it.
      A method of the MBean tries to load a XML file which is also packed into the JAR file.

      Everything works fine if I start the Application stand alone. But if I deploy the application in JBoss (that works - no problem) and calling the managed operation which should load the XML-File, well... crack... The MBean fails to find the XML file.

      What's the trick? A classpath problem?

      I'm trying to get an URL of the XML file by:

      URL url = ClassLoader.getSystemResource("resources/simple.xml");

      Hope anybody could help me ..

      Best regards,.
      Andreas Heidt

        • 1. Re: Accessing resources from within a MBean
          Nicholas Whitehead Novice

          Andreas;

          Part of the problem may be how you are using the SystemClassLoader to load the resorce. What you need is to use the MBean's own class loader, so in your code you should use something like

          this.getClass().getClassLoader().getSystemResource("resources/simple.xml");


          This is what works for our code:

          InputStream is = this.getClass().getResourceAsStream(resourceName);


          Cheers.

          //Nicholas