Uploaded image for project: 'TomEE'
  1. TomEE
  2. TOMEE-1547

Use application classloader for resources defined in resources.xml

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 1.7.1
    • 7.0.0-M1
    • None
    • None

    Description

      Resources can be defined in applications using META-INF/resources.xml. This is a useful feature, but because resources are created very early on in deployment the final classloader for the application is not available.

      I know I can manually specify a specific jar or classpath, but I specifically want the resources I define to be loaded using the same classpath the application uses.

      So, for example, if I have an EJB jar in an EAR, and the EJB jar contains a POJO called HelloBean, the following should load the resource from the application classloader:

      <Resources>
      <Resource id="Hello" type="org.superbiz.HelloBean">
      property1 value1
      property2 value2
      </Resource>
      </Resources>

      Currently this fails with a class not found error, due to the following in org.apache.openejb.assembler.classic.Assembler.createResource(ResourceInfo):

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

      boolean customLoader = false;
      try {
      if (serviceInfo.classpath != null && serviceInfo.classpath.length > 0) {
      final URL[] urls = new URL[serviceInfo.classpath.length];
      for (int i = 0; i < serviceInfo.classpath.length; i++)

      { urls[i] = serviceInfo.classpath[i].toURL(); }

      loader = new URLClassLoaderFirst(urls, loader);
      customLoader = true;
      }
      } catch (final MalformedURLException e)

      { throw new OpenEJBException("Unable to create a classloader for " + serviceInfo.id, e); }

      Object service = serviceRecipe.create(loader);

      Attachments

        Activity

          People

            jgallimore Jonathan Gallimore
            jgallimore Jonathan Gallimore
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: