question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ClassNotFound Exception with classes of my own project 5.5.1

See original GitHub issue

I am developing a project using playframework and when I try to use dozer for some mappings, I get a ClassNotFoundException with classes that are part of my own project. I suspect it has something to do with the class loader (as explained here) of play, which might not be compatible with this version (even though when using dozer 5.4.0 I have no problem at all)

[info] play.api.Play$ - Application started (Dev)
[info] o.d.DozerBeanMapper - Initializing a new instance of dozer bean mapper.
[info] o.d.DozerBeanMapper - Using the following xml files to load custom mappings for the bean mapper instance: [dozerMapping.xml]
[info] o.d.DozerBeanMapper - Trying to find xml mapping file: dozerMapping.xml
[info] o.d.DozerBeanMapper - Using URL [file:/Users/cdparra/Projects/appcivist/appcivist-platform/target/scala-2.11/classes/dozerMapping.xml] to load custom xml mappings
[error] o.d.l.x.MappingStreamReader - Error while loading dozer mapping InputStream: [java.io.BufferedInputStream@1fd14bad]
org.dozer.MappingException: java.lang.ClassNotFoundException: models.location.Location
    at org.dozer.util.MappingUtils.throwMappingException(MappingUtils.java:82) ~[dozer-5.5.1.jar:na]
    at org.dozer.util.DefaultClassLoader.loadClass(DefaultClassLoader.java:43) ~[dozer-5.5.1.jar:na]
    at org.dozer.util.MappingUtils.loadClass(MappingUtils.java:224) ~[dozer-5.5.1.jar:na]
    at org.dozer.loader.DozerBuilder$MappingBuilder.classA(DozerBuilder.java:129) ~[dozer-5.5.1.jar:na]
    at org.dozer.loader.xml.XMLParser.parseMapping(XMLParser.java:190) ~[dozer-5.5.1.jar:na]
    at org.dozer.loader.xml.XMLParser.read(XMLParser.java:137) ~[dozer-5.5.1.jar:na]
    at org.dozer.loader.xml.XMLParser.read(XMLParser.java:43) ~[dozer-5.5.1.jar:na]
    at org.dozer.loader.xml.MappingStreamReader.read(MappingStreamReader.java:51) ~[dozer-5.5.1.jar:na]
    at org.dozer.loader.xml.MappingFileReader.read(MappingFileReader.java:58) [dozer-5.5.1.jar:na]
    at org.dozer.DozerBeanMapper.loadFromFiles(DozerBeanMapper.java:227) [dozer-5.5.1.jar:na]
Caused by: java.lang.ClassNotFoundException: models.location.Location
    at java.net.URLClassLoader$1.run(URLClassLoader.java:372) ~[na:1.8.0_25]
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361) ~[na:1.8.0_25]
    at java.security.AccessController.doPrivileged(Native Method) ~[na:1.8.0_25]
    at java.net.URLClassLoader.findClass(URLClassLoader.java:360) ~[na:1.8.0_25]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_25]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_25]
    at java.lang.Class.forName0(Native Method) ~[na:1.8.0_25]
    at java.lang.Class.forName(Class.java:344) ~[na:1.8.0_25]
    at org.apache.commons.lang3.ClassUtils.getClass(ClassUtils.java:909) ~[commons-lang3-3.4.jar:3.4]
    at org.apache.commons.lang3.ClassUtils.getClass(ClassUtils.java:943) ~[commons-lang3-3.4.jar:3.4]

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:7

github_iconTop GitHub Comments

6reactions
christianmenzcommented, Apr 7, 2016

Took me quite a while to figure out what the problem was for me. I can’t tell for sure as I don’t know your exact setup, but maybe this helps other people searching for a solution. I’m using dozer in an enterprise application and dozer jar is loaded by the EARLibClassLoader (the app by the EARAppClassLoader).

Dozer does this:

DozerClassLoader classLoader = new DefaultClassLoader(getClass().getClassLoader());

Which imho is the wrong classloader for loading the classes in my dozer mapping file. I fixed this by adding this line of code before creating the mapper:

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

0reactions
garethahealycommented, Apr 5, 2017
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Fix ClassNotFoundException in Java - Rollbar
The Java ClassNotFoundException occurs when the JVM tries to load a class but does not find it in the classpath. Learn the three...
Read more >
Class not found error, but class definitely exists - java
At first "Clean" and "Sync Project with Gradle Files". Then run your code.
Read more >
ClassNotFoundException vs NoClassDefFoundError - Baeldung
Both ClassNotFoundException and NoClassDefFoundError occur when the JVM can not find a requested class on the classpath.
Read more >
Configure jrun4 in myEclipse 5.5.1 GA - Genuitec
Everything seems fine except that the jars in my project classpath are not ... ClassNotFoundException: com.uhc.ubh.laww.cert.controller.
Read more >
Virgo » Error configuring application listener - Eclipse
I guess you want to make the Spring XmlWebApplicationContext class available through the osgi mechanism. But our own com.myCompany.myApps.web.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found