已有51人关注
Tomcat不能正常启动,提示java.lang.NoClassDefFoundError:org/apache/commons/logging/logFactory
发表在JavaWeb答疑区 2017-06-18
是否精华
版块置顶:

老师,您好!我将操作Java Web开发实战1200例(第1卷)的182例部署好后,启动Tomcat时,就报java.lang.NoClassDefFoundError:org/apache/commons/logging/logFactory

at com.mr.LogFiter.<init>(LogFiter.java:18),我已经加入了org-apache-commons-logging.jar和 log4j-1.2.14jar两个包,但还是报错,请老师有空帮看一下,十分感谢!

分享到:
精彩评论 9
silence雪
学分:378 LV5
2017-06-19
沙发

你好:

目前这边暂时没有光盘源码,你看一下com.mr.LogFiter这个类里面第18行是什么代码?

这个类有没有报错?

一般出现这个错误是因为缺少包导致的。

jzy81208
学分:71 LV3
2017-06-19
板凳

老师,您好!

第18行代码:private Log log = LogFactory.getLog(this.getClass());

以下是所有的:

package com.mr;


import java.io.IOException;


import javax.servlet.Filter;

import javax.servlet.FilterChain;

import javax.servlet.FilterConfig;

import javax.servlet.ServletException;

import javax.servlet.ServletRequest;

import javax.servlet.ServletResponse;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;

import org.apache.commons.logging.LogFactory;


public class LogFilter implements Filter {


private Log log = LogFactory.getLog(this.getClass());


private String filterName;


public void init(FilterConfig config) throws ServletException {


filterName = config.getFilterName();//获取 Filter的 name,启动Filter

log.info("启动 Filter: " + filterName);//

}

public void doFilter(ServletRequest req, ServletResponse res,

FilterChain chain) throws IOException, ServletException {


HttpServletRequest request = (HttpServletRequest) req;

HttpServletResponse response = (HttpServletResponse) res;


long startTime = System.currentTimeMillis();//运行前的时间

String requestURI = request.getRequestURI();//获取访问的URI


requestURI = request.getQueryString() == null ? requestURI//所有的地址栏参数对比

: (requestURI + "?" + request.getQueryString());


chain.doFilter(request, response);


long endTime = System.currentTimeMillis();

//消耗的总时间

log.info(request.getRemoteAddr() + " 访问了 " + requestURI + ", 总用时 "

+ (endTime - startTime) + " 毫秒。");

}

public void destroy() { //销毁时记录日志

}

}


silence雪
学分:378 LV5
2017-06-21
地板

jzy81208 发表于2017-06-19 14:22

老师,您好!

第18行代码:private Log log = LogFactory.getLog(this.getClass());

以下是所有的:

package com.mr;


import java.io.IOException;


import javax.servlet.Filter;

import javax.servlet.FilterChain;

import javax.servlet.FilterConfig;

import javax.servlet.ServletException;

import javax.servlet.ServletRequest;

import javax.servlet.ServletResponse;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;

import org.apache.commons.logging.LogFactory;


public class LogFilter implements Filter {


private Log log = LogFactory.getLog(this.getClass());


private String filterName;


public void init(FilterConfig config) throws ServletException {


filterName = config.getFilterName();//获取 Filter的 name,启动Filter

log.info("启动 Filter: " + filterName);//

}

public void doFilter(ServletRequest req, ServletResponse res,

FilterChain chain) throws IOException, ServletException {


HttpServletRequest request = (HttpServletRequest) req;

HttpServletResponse response = (HttpServletResponse) res;


long startTime = System.currentTimeMillis();//运行前的时间

String requestURI = request.getRequestURI();//获取访问的URI


requestURI = request.getQueryString() == null ? requestURI//所有的地址栏参数对比

: (requestURI + "?" + request.getQueryString());


chain.doFilter(request, response);


long endTime = System.currentTimeMillis();

//消耗的总时间

log.info(request.getRemoteAddr() + " 访问了 " + requestURI + ", 总用时 "

+ (endTime - startTime) + " 毫秒。");

}

public void destroy() { //销毁时记录日志

}

}


你好:

sorry啊~最近有些忙,没看到你回复的,看你上述代码,看来还是包错误。给你传个这个commons-logging-1.1.1.jar,看看是否可用。

commons-logging-1.1.1.rar


jzy81208
学分:71 LV3
2017-06-21
4L

谢谢老师!问题终于解决了。不好意思,还有一个同样的问题,Java Web开发实战1200例(第1卷)的实例191也需要包common-fileupload.jar,教材说光盘上的lib目录下有,但里面是空的。网上下载了,同样不能用啊。再次麻烦老师也发一个给我,给你添麻烦了,太感谢了!

无语_mrkj
学分:3155 LV11
2017-06-22
5L

您试一下附件中的这两个Jar包,看看哪个可以。

commons-fileupload.rar


jzy81208
学分:71 LV3
2017-06-22
6L

好的,谢谢老师!


jzy81208
学分:71 LV3
2017-06-23
7L

老师,早,昨天的两个包打上去,还是报错啊,后来我网上下载了commons-fileupload-1.3.2.jar包打上去,也报错啊,提示找不到类DiskFileUpload,请老师百忙中帮看一下,十分感谢!具体提示如下:

java.lang.ClassNotFoundException: org.apache.commons.fileupload.DiskFileUpload

at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1387)

at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1233)

at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)

at com.count.Online.UploadRw.<init>(UploadRw.java:37)

at com.count.Online.UploadFilter.doFilter(UploadFilter.java:20)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)

at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)

at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)

at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)

at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)

at java.lang.Thread.run(Thread.java:619)


silence雪
学分:378 LV5
2017-06-23
8L

jzy81208 发表于2017-06-23 08:46

老师,早,昨天的两个包打上去,还是报错啊,后来我网上下载了commons-fileupload-1.3.2.jar包打上去,也报错啊,提示找不到类DiskFileUpload,请老师百忙中帮看一下,十分感谢!具体提示如下:

java.lang.ClassNotFoundException: org.apache.commons.fileupload.DiskFileUpload

at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1387)

at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1233)

at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)

at com.count.Online.UploadRw.<init>(UploadRw.java:37)

at com.count.Online.UploadFilter.doFilter(UploadFilter.java:20)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)

at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)

at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)

at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)

at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)

at java.lang.Thread.run(Thread.java:619)


你好:

可能由于版本过高引起的,试着找commons-fileupload-1.0.jar 这个版本。

jzy81208
学分:71 LV3
2017-06-23
9L

好的,谢谢!我试试。


首页上一页 1 下一页尾页 9 条记录 1/1页
手机同步功能介绍
友情提示:以下图书配套资源能够实现手机同步功能
明日微信公众号
明日之星 明日之星编程特训营
客服热线(每日9:00-17:00)
400 675 1066
mingrisoft@mingrisoft.com
吉林省明日科技有限公司Copyright ©2007-2022,mingrisoft.com, All Rights Reserved长春市北湖科技开发区盛北大街3333号长春北湖科技园项目一期A10号楼四、五层
吉ICP备10002740号-2吉公网安备22010202000132经营性网站备案信息 营业执照