获取 java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory 异常

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1551697/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 14:01:50  来源:igfitidea点击:

Getting java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory exception

javanoclassdeffounderror

提问by

i am executing simple Dependency Injection program of spring & getting this exception. I have already included common-logging1.1.1.jar and spring.jar file. Could you please help to out?

我正在执行 spring 的简单依赖注入程序并得到这个异常。我已经包含了 common-logging1.1.1.jar 和 spring.jar 文件。你能帮帮忙吗?

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
    at org.springframework.context.support.AbstractApplicationContext.<init>(AbstractApplicationContext.java:119)
    at org.springframework.context.support.AbstractXmlApplicationContext.<init>(AbstractXmlApplicationContext.java:55)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:77)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:65)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:56)
    at com.client.StoryReader.main(StoryReader.java:15)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
    at java.net.URLClassLoader.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    ... 6 more

回答by emills

Try doing a complete clean of the target/deployment directory for the app to get rid of any stale library jars. Make a fresh build and check that commons-logging.jar is actually being placed in the correct lib folder. It might not be included when you are building the library for the application.

尝试彻底清除应用程序的目标/部署目录,以摆脱任何陈旧的库 jar。重新构建并检查 commons-logging.jar 是否实际放置在正确的 lib 文件夹中。当您为应用程序构建库时,它可能不包括在内。

回答by Jesper

I have already included common-logging1.1.1.jar and ...

我已经包含了 common-logging1.1.1.jar 和 ...

Are you sure you spelled the name of the JAR file exactly right? I think it should probably be commons-logging-1.1.1.jar(note the extra -in the name). Also check if the directory name is correct.

您确定您拼写的 JAR 文件名完全正确吗?我认为它可能应该是commons-logging-1.1.1.jar(注意-名称中的额外内容)。还要检查目录名称是否正确。

NoClassDefFoundErroralways means that a class cannot be found, so most likely your class path is not correct.

NoClassDefFoundError始终意味着找不到类,因此很可能您的类路径不正确。

回答by dhammikas

Just check whether the commons-logging.jar has been added to your libs and the classpath.. I had the same issue and that was because of this. dhammikas-

只需检查 commons-logging.jar 是否已添加到您的库和类路径中..我遇到了同样的问题,就是因为这个。法门——

回答by brianegge

I generally assign the classpath to a variable and then verify it. I've written a small ruby script which I include in a my startup scripts which validates the classpath before launching java. Validating the classpath before the JVM starts has saved me lots of time troubleshooting these types of problems.

我通常将类路径分配给一个变量,然后对其进行验证。我写了一个小的 ruby​​ 脚本,我将它包含在我的启动脚本中,它在启动 java 之前验证类路径。在 JVM 启动之前验证类路径为我节省了大量时间来解决这些类型的问题。

回答by Manikandan

I have also faced the same issues, to fix, download the jar files from the below url

我也遇到了同样的问题,要修复,请从以下网址下载 jar 文件

http://commons.apache.org/logging/download_logging.cgi

http://commons.apache.org/logging/download_logging.cgi

and copy to your lib folder, will resolve your issue.

并复制到您的 lib 文件夹,将解决您的问题。

回答by rash

http://commons.apache.org/logging/download_logging.cgi

http://commons.apache.org/logging/download_logging.cgi

use this url to download jar files and include them in your class path, issue will be solved

使用此 url 下载 jar 文件并将它们包含在您的类路径中,问题将得到解决

回答by sonida

You just download commons-logging-1.1.2.jarand then copy this file in to libs

您只需下载commons-logging-1.1.2.jar然后将此文件复制到 libs

finally, it works.

最后,它起作用了。

回答by stacky

I had the same problem, and solved it by just adding the commons-logging.jarto the class path.

我遇到了同样的问题,只需将commons-logging.jar加到类路径中即可解决。

回答by Tush

Issue solved by adding commons-logging.jar

通过添加 commons-logging.jar 解决的问题

Imp files are ,

Imp 文件是,

antlr-runtime-3.0.1

org.springframework.aop-3.1.0.M2

org.springframework.asm-3.1.0.M2

org.springframework.aspects-3.1.0.M2

org.springframework.beans-3.1.0.M2

org.springframework.context.support-3.1.0.M2

org.springframework.context-3.1.0.M2

org.springframework.core-3.1.0.M2

org.springframework.expression-3.1.0.M2

commons-logging-1.1.1

回答by asuka

If you're using maven for managing dependencies, add the following line in your pom.xml:

如果您使用 maven 管理依赖项,请在 pom.xml 中添加以下行:

<dependency>
        <groupId>commons-logging</groupId>
        <artifactId>commons-logging</artifactId>
        <version>1.1.1</version>
</dependency>