ankush981
ankush981

Reputation: 5417

Java class not found in Jackson

I'm new to Java and have a program that's throwing the following error:

Exception in thread "main" java.lang.NoClassDefFoundError: org/codehaus/jackson/map/ObjectMapper
    at ExtractCustomerIds.main(ExtractCustomerIds.java:21)
Caused by: java.lang.ClassNotFoundException: org.codehaus.jackson.map.ObjectMapper
    at jdk.internal.loader.BuiltinClassLoader.loadClass(java.base@9-internal/BuiltinClassLoader.java:366)
    at jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(java.base@9-internal/ClassLoaders.java:184)
    at java.lang.ClassLoader.loadClass(java.base@9-internal/ClassLoader.java:419)
    ... 1 more

I know the problem has to be with paths, classpath or jar name, but I can't figure out as of now.

My folder structure is:

.
 - get_customer_ids
   - ExtractCustomerIds.java
 - libs
   - jackson-all-1.9.11.jar

So when I'm inside the get_customer_ids I give the following command:

get_customer_ids$ javac -cp ../libs/* ExtractCustomerIds.java and this causes the error above.

I thought I was setting the classpath correctly, but it's still not working. What's missing?

Upvotes: 0

Views: 1402

Answers (1)

Michael Rose
Michael Rose

Reputation: 7820

The exception occurs when running your program - you are specifying the classpath while compiling. The classpath set during compilation is not stored inside the compiled class files or the like - you need to correctly specify it when running your program, too!

Like so:

$ java -cp ../libs/* ExtractCustomerIds

Upvotes: 5

Related Questions