You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by "Jonathan Gallimore (JIRA)" <ji...@apache.org> on 2015/04/14 12:03:12 UTC

[jira] [Created] (TOMEE-1547) Use application classloader for resources defined in resources.xml

Jonathan Gallimore created TOMEE-1547:
-----------------------------------------

             Summary: Use application classloader for resources defined in resources.xml
                 Key: TOMEE-1547
                 URL: https://issues.apache.org/jira/browse/TOMEE-1547
             Project: TomEE
          Issue Type: Improvement
    Affects Versions: 1.7.1
            Reporter: Jonathan Gallimore
            Assignee: Jonathan Gallimore
             Fix For: 2.0.0-Milestone-1, 1.7.2


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);
      



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)