java.lang.ClassNotFoundException / NoClassDefFoundError for com/fasterxml/jackson/databind/ObjectMapper with Maven

ur-vogel picture ur-vogel · Sep 26, 2014 · Viewed 50k times · Source

I get the following error when trying to run a java program that uses jackon's ObjectMapper class:

Exception in thread "main" java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/ObjectMapper
  at com.inin.dynamotransfer.DynamoTransfer.importData(DynamoTransfer.java:133)
  at com.inin.dynamotransfer.DynamoTransfer.main(DynamoTransfer.java:67)
Caused by: java.lang.ClassNotFoundException: com.fasterxml.jackson.databind.ObjectMapper
  at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
  at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
  at java.security.AccessController.doPrivileged(Native Method)
  at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
  ... 2 more

I have the Jackson annotations, databind (which contains ObjectMapper), and core JARs in my Maven repository under ~/.m2/repository/com/fasterxml/jackson/core/jackson-[packagename]/2.4.0. here's the dependencies section of my pom.xml:

<dependencies>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-annotations</artifactId>
        <version>2.4.0</version>
    </dependency>

    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>2.4.0</version>
    </dependency>

    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-core</artifactId>
        <version>2.4.0</version>
    </dependency>
</dependencies>

here's my CLASSPATH:

:/Users/myusername/Library/Java/Extensions:/Library/Java/Extensions:/Users/myusername/.m2/repository

so Maven knows all about these JARs - where to get em, where to put em, etc. - but java itself can't seem to find the classes I need. what am I doing wrong?? thanks!

Answer

Oleksii Kyslytsyn picture Oleksii Kyslytsyn · Aug 18, 2015

try to redo maven lifecycle goals:

mvn clean install -U