dotslash dotslash - 1 year ago 47
Java Question

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(
Caused by: java.lang.ClassNotFoundException:
at jdk.internal.loader.BuiltinClassLoader.loadClass(java.base@9-internal/
at jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(java.base@9-internal/
at java.lang.ClassLoader.loadClass(java.base@9-internal/
... 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
- libs
- jackson-all-1.9.11.jar

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

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

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

Answer Source

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download