简体   繁体   English

如何修复:BoneCP中线程“main”java.lang.NoClassDefFoundError中的异常

[英]How to fix: Exception in thread “main” java.lang.NoClassDefFoundError in BoneCP

I'm working from this example and I am running into this error after adding log4j, slf4j and bonecp to the project: 我正在使用这个示例,在将log4j,slf4j和bonecp添加到项目后,我遇到了这个错误:

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)

In addition to BoneCP and SLF4J, you need to add Google Guava , because BoneCP's requirements page states that it needs to be present. 除了BoneCP和SLF4J之外,您还需要添加Google Guava ,因为BoneCP的需求页面指出它需要存在。 Download guava-*.jar and add it to your classpath the same way you did with SLF4J and BoneCP. 下载guava-*.jar并将其添加到类路径中,就像使用SLF4J和BoneCP一样。

You will need to add those jars to the classpath of your Java process when you run it. 运行它时,您需要将这些jar添加到Java进程的类路径中。 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. 这假设jar位于名为lib的目录中,该目录位于执行Java命令的目录中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM