6 Replies Latest reply on Dec 9, 2011 5:26 AM by jaabax

    Find classes on EAR/lib through a MBean within a SAR

    jaabax Newbie

      Hi.

      I have a SAR inside an EAR and an entity beans JAR file inside EAR/lib directory.

      so:

       

      my-app.ear

      |   lib/

      |    |_ my-app-entity-beans.jar

      |    |_ more-classes.jar

      |_my-app-sar.sar

      |_my-app-ejb.jar

      |_my-app-web.war

       

      I need that my MBean inside my-app-sar.sar find all classes inside my-app-entity-beans.jar.

      I have a code that works perfectly on JBoss 4, 5 (never tested on JBoss 6).

      I piece of code:

       

      {code}

      ...

      ClassLoader cld = Thread.currentThread().getContextClassLoader();

       

      Enumeration<URL> resources = cld.getResources(packageName.replace('.', '/'));

       

      List<Class<?>> classes = new ArrayList<Class<?>>();

       

      while (resources.hasMoreElements()) {

         Enumeration<JarEntry> entries = ((JarURLConnection) resources.nextElement().openConnection()).getJarFile().entries();

       

         while (entries.hasMoreElements()) {

            JarEntry entry = entries.nextElement();

            if (entry.getName().endsWith(".class")) {

               String strClazz = entry.getName().replace('/', '.');

               classes.add(Class.forName(strClazz.substring(0, strClazz.length() - 6)));

            }

         }

      }

      ...

      {code}

       

      This code is executed when I start JBoss 7 (only when I start the server).

      But this code does not work on JBoss 7.

      How can I achieve this goal?

      Thanks in advance!