bgarrels / zipscript

Automatically exported from code.google.com/p/zipscript
0 stars 0 forks source link

ClassPathResourceLoader should also look for the resource in the system classloader as well #31

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
This is the code I have for loading a template from a classpath and
providing it to groovy

        InputStream is = TemplateUtils.class.getResourceAsStream(templatePath);
        if (is == null)
        {
            is = ClassLoader.getSystemResourceAsStream(templatePath);
        }
        return is;

TemplateUtils is my current class.

I want to load the Zip Script template the same way. However it fails with
a class not found error.

The getResource method in ClassPathResourceLoaded needs to be changed to do
the following.

        InputStream is =
Thread.currentThread().getContextClassLoader().getResourceAsStream(
                getRealPath(path));
        if (null == is) {
            is = ClassLoader.getSystemResourceAsStream(templatePath);
        }
        if (null == is) {
            throw new ExecutionException("Invalid classpath resource '" +
getRealPath(path), null);
        }
        return new StreamOnlyResource(is);
    }

basically an additional line to try from the system classloader

Original issue reported on code.google.com by roshan...@gmail.com on 10 Jul 2008 at 7:58

GoogleCodeExporter commented 9 years ago
fixed - thanks for the input

Original comment by joe...@gmail.com on 10 Jul 2008 at 9:10