0 Replies Latest reply on Aug 6, 2014 3:51 AM by Amal Raj Vinoth James

    Jboss AS 7.1.1 Final : Add resources dynamically to custom module classpath.

    Amal Raj Vinoth James Newbie

      Hi,

       

      We have a requirement to load user defined classes dynamically without bouncing the servers. User created class files are placed (along with package folder) in a predefined location. This folder location is added in system classpath of the server.

       

      We have our own classloader implementation (FileClassLoader) which looks for classes/resources in the paths provided. Using this classloader we load the classes dynamically searching for a file in these paths. If file is not found we delegate it to its parent classloader. The parent classloader is a ejb classloader and it searches for class in the system classpath.

      Using this approach we load the classes dynamically.

       

      For example,

       

      In system classpath we have added: app/resources/common/classes and when the class say com.company.Test is placed under app/resources/common/classes/com/company folder, we were able to load it with above approach.

      This is working with JBoss 5x

       

      In case of JBoss 7x, we do not have system classpath. We have defined a module which has following entry:

      <resource-root path="../resources/common/bo/classes"/>

       

      and this module is added as a global module. Now here when FileClassLoader is created its parent is ModuleClassLoader (EAR's module loader).

       

      Observation:

      When com.company.Test is searched by parent it throws ClassNotFoundException.

      The .index file which got created for above module on server startup contains entry like /ebmsapps/common/bo/classes

       

      If we delete this index file and restart the server, jboss regenerates .index file again with following additional entries:

      /resources/common/classes/com

      /resources/common/classes/com/company

       

      Now if the class com.company.Test is searched by parent Class loader(EAR's module loader) then it is found.

       

      Basically it works only when the entry for that folder is present in the .index file.

       

      We have following questions in this regard:

      1. How to load the classes dynamically which are outside of EAR and WAR package?

      2. Is there any way to re-create the .index file dynamically when class files are added in bo\classes folder?

      3. Any way to disable this .index file generation or any work around?

       

      Options tried:

      We are tring to refresh ResourceLoaders using following mbean invocation:

       

      refreshResourceLoaders on the mbean: jboss.modules:type=ModuleLoader,name=LocalModuleLoader-3 for a module

       

      Code:

       

      public static void refreshResourceLoaders() {
          ObjectName name = null;      
          try {
              String urlString = System.getProperty("jmx.service.url","service:jmx:remoting-jmx://localhost:9999");
              JMXServiceURL serviceURL = new JMXServiceURL(urlString);
              JMXConnector jmxConnector = JMXConnectorFactory.connect(serviceURL, null);
              MBeanServerConnection connection = jmxConnector.getMBeanServerConnection();
            
              name = new ObjectName("jboss.modules:type=ModuleLoader,name=LocalModuleLoader-3");
              connection.invoke(name, "refreshResourceLoaders",
                      new Object[] { "com.company.test" },
                      new String[] { String.class.getName() });
          } catch (Throwable th) {
              throw new RuntimeException("Error invoking MBean ["+name+"]", th);
          }
      }
      
      
      

      Invoking above code,after deletting the .index file, it is regenerating .index file with proper entries(newly added classes), but ejb-jar module loader could not find the newly added class which is added at runtime. If we restart the server, then it can able see the class newly added. It look like MBean refreshResourceLoaders is not working.

       

      Any help would be appreciated.

       

      Thanks,

      Amal