How to fix: Exception in thread “main” java.lang.NoClassDefFoundError in BoneCP
Question
I'm working from this example and I am running into this error after adding log4j, slf4j and bonecp to the project:
run:
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/base/FinalizableReferenceQueue
at com.jolbox.bonecp.BoneCP.<init>(BoneCP.java:321)
at javasampleapps.BoneCPExample.main(BoneCPExample.java:35)
Caused by: java.lang.ClassNotFoundException: com.google.common.base.FinalizableReferenceQueue
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
... 2 more
Java Result: 1
BUILD SUCCESSFUL (total time: 3 seconds)
Solution
In addition to BoneCP and SLF4J, you need to add Google Guava, because BoneCP's requirements page states that it needs to be present. Download guava-*.jar
and add it to your classpath the same way you did with SLF4J and BoneCP.
OTHER TIPS
You will need to add those jars to the classpath of your Java process when you run it. For example,
java -classpath lib/log4j.jar;lib/slf4j.jar;lib/bonecp.jar [your_class]
This assumes that the jars are in a dir called lib which is in the directory you execute the Java command from.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow