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

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

我正在执行spring的简单Dependency Injection程序并获取此异常。
我已经包含了common-logging1.1.1.jar和spring.jar文件。 你能帮忙吗?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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$1.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


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

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

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


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

1
2
3
4
5
<dependency>
        <groupId>commons-logging</groupId>
        commons-logging</artifactId>
        <version>1.1.1</version>
</dependency>


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

终于,它起作用了。


commons-logging-1.1.1.jar或jcl-over-slf4j-1.7.6.jar等

如果使用的是maven,请使用以下代码。

1
2
3
4
5
<dependency>
    <groupId>org.slf4j</groupId>
    jcl-over-slf4j</artifactId>
    <version>${slf4j.version}</version>
</dependency>


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


添加commons-logging.jar或commons-logging-1.1.jar将解决此问题...


设置编译范围对我有用

1
2
3
4
5
6
<dependency>
  <groupId>commons-logging</groupId>
  commons-logging</artifactId>
  <version>1.2</version>
  <scope>compile</scope>
</dependency>


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

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

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


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

Imp文件是,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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

尝试彻底清除该应用程序的target / deployment目录,以摆脱所有过时的库jar。重新构建并检查commons-logging.jar实际上是否放置在正确的lib文件夹中。在为应用程序构建库时,可能不包括它。


我也遇到了同样的麻烦。
最后,我检查了具有该类的apache版本。
我发现版本1.0.4具有该类。

尝试使用版本1.0.4而不是1.1.X或1.2.X

我的依赖:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
    <dependencies>
        <dependency>
            <groupId>org.jolokia</groupId>
            jolokia-core</artifactId>
            <version>1.3.5</version>
        </dependency>
        <dependency>
            <groupId>org.jolokia</groupId>
            jolokia-client-java</artifactId>
            <version>1.3.5</version>
        </dependency>
        <dependency>
            <groupId>commons-logging</groupId>
            commons-logging</artifactId>
            <version>1.0.4</version>
        </dependency>
    </dependencies>

我的Java代码

1
2
3
4
5
J4pClient j4pClient = new J4pClient("http://localhost:8080/jolokia");
J4pReadRequest req = new J4pReadRequest("java.lang:type=Memory","HeapMemoryUsage");
req.setPath("used");
J4pReadResponse resp = j4pClient.execute(req);
System.out.println(resp.getValue());

我的结果:

1
130489168

还要仔细检查您的Maven依赖项是否已正确导入。


两个选项(至少):

  • 通过将commons-logging jar添加到文件中,方法是将其复制到本地文件夹中。
  • 注意:链接jar可能会导致服务器出现问题,也可能是将其添加到构建路径但不能解决服务器启动问题的原因。

    因此,请勿将罐子指向外部文件夹。

    要么...

  • 如果您真的不想在本地添加它,因为要在项目之间共享jar,那么...
  • 如果使用的是tc服务器实例,则需要将jar作为外部jar添加到服务器实例运行配置中。

    依次运行为,运行配置...,{您的tc服务器实例},然后单击"类路径"选项卡。

    然后添加commons-logging jar。


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

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


    嘿,我在tutorialpoint.com上关注本教程。完成第2步-安装Apache Common Logging API后添加:您必须从在此步骤下载的文件中将外部jar库导入到项目中。对我来说,文件名为" commons-logging-1.1.1"。


    我通常将classpath分配给变量,然后对其进行验证。我编写了一个小的ruby脚本,该脚本包含在启动脚本中,该脚本在启动Java之前先验证类路径。在JVM启动之前验证类路径为我节省了很多时间来排查这些类型的问题。


    只需检查commons-logging.jar是否已添加到您的库和类路径中即可。我有同样的问题,这就是因为这个原因。
    达米卡斯-


    以我为例,我正在Eclipse中测试Tomcat应用程序,但收到此错误。我通过检查.classpath文件解决了该问题,并更正了此条目:

    1
    2
    3
    4
    5
    6
    <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
       
           
           
        </attributes>
    </classpathentry>

    属性org.eclipse.jst.component.dependency已丢失。


    如果您是在Android上运行此程序,请注意,显然java.beans包在Android上尚未完成。要尝试在Android上修复它,请尝试以下操作:

  • 下载android-java-air-bridge.jar(当前下载按钮位于页面底部或直接链接至此处)
  • 将下载的jar复制到您的[APPROOT] / app / libs目录(或以其他任何方式链接jar)
  • import ***语句更改为air-bridge。例如import javadz.beanutils.BeanUtils而不是import org.apache.commons.beanutils.BeanUtils;
  • 清理并重建项目
  • 源1,源2

    我很抱歉,因为我意识到这并不能完全回答问题,尽管在搜索android生成的NoClassDefFoundError: Failed resolution of: beanUtils错误时会出现很多SO页面。


    罐子出现时我遇到了同样的错误。没有解决方案。起作用的是从文件系统(从.m2目录中)删除jar,然后清理maven项目。


    我在Eclipse IDE中遇到相同的问题,我的解决方案是:
    右键单击我的项目>属性

    enter image description here

    在Maven中单击并编写:Active Maven项目中的jar

    enter image description here

    最后,申请并关闭


    检查罐子是否正确导入。我使用构建路径导入了它们。但是它无法识别WAR / lib文件夹中的jar。后来,我将相同的jar复制到war / lib文件夹。现在工作正常。您可以刷新/清理您的项目。


    朋友您好,如果您在休眠代码中发现任何未分类的异常,则是jar文件的问题。这里主要有两个问题
    1.我的意思是说您的休眠版本较旧,可能是3.2以下。因此,如果您尝试使用3.6以上的版本,它将可以正常工作

    2.首先检查数据库连接。如果数据库正常工作,则说明您的程序或jar文件中存在错误。

    如果您尝试使用IDE,也请检查这两个问题是否仍然无法解决。我正在使用netbeanside 6.9版本。在这里,hibernate工作正常。您没有从类非基础异常中得到任何错误。

    希望这对您有所帮助


    解决方案是添加common-logging.x.x jar文件


    尝试添加此依赖项

    org.apache.commons
    下议院执行官
    1.3


    如果所有其他方法都失败了,请尝试将commons-logging-x.y.z.jar放入Tomcat的lib目录中。它解决了问题!顺便说一句,我正在使用Tomcat 6。