J.Azur J.Azur -4 years ago 153
Java Question

Dozer instantiation in Web Service eclipse

I'm currently trying to use Dozer (5.5.1) on a Web Service to map data between two objects. I've successfully been able to perform the mapping in a simple java application and I'm trying to do it in a Dynamic Web Project in Eclipse.

When I'm trying to instanciate the mapper, I get this error:
Exception: java.lang.reflect.InvocationTargetException
(The line:DozerBeanMapper mapper = new DozerBeanMapper();)

I search for my problem and I've seen it could be a classloader problem, so I tried to resolve it using this:

BeanContainer.getInstance().setClassLoader(new DefaultClassLoader(Thread.currentThread().getContextClassLoader()));

But then, this error occurs:
Exception: java.lang.NoClassDefFoundError: org/dozer/util/DozerClassLoader; nested exception is:
java.lang.NoClassDefFoundError: org/dozer/util/DozerClassLoader

I've include this jar to my projects:

  • dozer-osgi-5.5.1

  • commons-beanutils-1.9.3

  • commons-collections4-4.1

  • commons-lang3-3.5

  • jcl-over-slf4j-1.7.24

  • slf4j-api-1.7.24

  • slf4j-simple-1.7.24

Hope you can help. Thx

Answer Source

I've made searches on the net and I try many solutions but no one works. I finally find a solution which work with my build but I'm not sure it's the best way to do it.

Seems that the Dynamic Web Project use two differents source for JAR lib or at least 2 different classloader. I don't know why change the classloader don't work but I copy the jar used for Dozer in the Web-INF/Lib and I've finally been able to instantiate the Dozer class.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download