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!
The default maven plugin doesn't build a fat jar with dependencies.
To build a jar bundled with its dependencies so that we can execute it with
java -jar
, we can use maven-assembly-plugin, which packages the jar with the namexxx-jar-with-dependencies.jar
.Here is a sample
pom.xml
Now you should be able to run your jar with
try to redo maven lifecycle goals: