#60 need ability to load mapping files from outside of classpath

Nhat Vo

Currently, the net.sf.dozer.util.mapping.util.Loader
uses the context class loader to load the mapping
files. This requires the mapping files to be under the
classpath. Some applications perfer to put their
configuration files in an external location that allows
reloading, for example WEB-INF. You cannot reload the
resources that loaded by context class loader.

The suggested patch is to check to see if the resource
starts with 'file:', and if so, load from the file.
Otherwise load from the classloader.


  • Nhat Vo

    Nhat Vo - 2006-09-21

    suggested patch.

  • Matt Tierney

    Matt Tierney - 2006-09-22

    Logged In: YES

    Thanks for the patch. We appreciate when patches are
    submitted along with the bug. I will take a look at this
    and if everything looks good, I will include it in the
    next release. I don't have a date for the next release
    but should be 4 - 8 weeks. Let me know if this is
    critical and you would need a formal release prior to
    that. I am guessing that your patch will get you by until
    the next release

  • Nhat Vo

    Nhat Vo - 2006-09-22

    properly load with File instead of use URL

  • Nhat Vo

    Nhat Vo - 2006-09-22

    Logged In: YES

    Thank you for the attention. It's pretty embarassing to say
    that the patch I posted doesn't work, because I only tested
    the class by itself. I posted another patch, and yes, I
    tested it again in the desired environment and It's working.

  • Matt Tierney

    Matt Tierney - 2006-09-26
    • assigned_to: nobody --> mhtierney
  • Matt Tierney

    Matt Tierney - 2006-09-27
    • status: open --> pending
  • Matt Tierney

    Matt Tierney - 2006-09-27

    Logged In: YES

    Hi Nhat,

    I applied your patch to the 2.4 code base. All appears to
    be ok with the code. The following is how I implemented
    the patch. Let me know if you see any issues. Thanks for

    public URL getResource(String resource) {
    URL result = Thread.currentThread

    // Could not find resource. Try with the classloader
    that loaded this class.
    if (result == null) {
    ClassLoader classLoader = Loader.class.getClassLoader
    if(classLoader != null) {
    result = classLoader.getResource(resource);

    // Last ditch attempt searching classpath
    if (result == null) {
    result = ClassLoader.getSystemResource(resource);

    //Patch to load mapping file from outside of classpath.
    if (resource.startsWith(FILE)) {
    try {
    return new File(resource.substring(FILE.length
    } catch (MalformedURLException e) {
    throw new MappingException(e);

    return result;

  • Matt Tierney

    Matt Tierney - 2006-10-16
    • status: pending --> closed

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks