3 Replies Latest reply on Aug 18, 2009 8:45 AM by Rolf Arne Corneliussen

    Add jar files to web application class loader runtime

    Rolf Arne Corneliussen Newbie

      We have a web application that support 'plug-ins', that is, a jar file that contains classes and various other resources.

      These jar files can be uploaded to the web application (a file upload) while it is running, and the classes inside the jar is supposed to be loaded and instantiated inside the web application.

      When using JBoss 4.2.2, the following code were used inside the web application:

      URLClassLoader loader = (URLClassLoader) getClass().getClassLoader();
      Class clazz = URLClassLoader.class;
      Method method = clazz.getDeclaredMethod( "addURL", new Class[]{URL.class} );
      method.setAccessible( true );
      method.invoke( loader, new Object[]{ url } );

      However, in JBoss 5 the class loader returned is BaseClassLoader, and it does not have the 'addURL' method.

      What is the recommended method to load classes into a web application from an arbitrary jar file in JBoss 5?