Tomcat中使用commons-io-2.5发生的错误java.lang.ClassNotFoundException: org.apache.commons.io.IOUtils

关键词:IntelliJ IDEA、Tomcat、commons-io-2.5.jar、java.lang.ClassNotFoundException: org.apache.commons.io.IOUtils

1、错误提示信息

图1 运行登录时错误信息

//Tomcat Localhost Log信息
org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [Servlet] in context with path [] threw exception [Servlet execution threw an exception] with root cause
 java.lang.ClassNotFoundException: org.apache.commons.io.IOUtils
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1269)
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1104)
    at servlet.Servlet.doGet(Servlet.java:29)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:475)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:651)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:498)
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:796)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1374)
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)

2、java文件内容

 @WebServlet(name = "Servlet",urlPatterns = "/Servlet")
 public class Servlet extends HttpServlet {
     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
         Class c = this.getClass();
         InputStream input = c.getResourceAsStream("a.txt");
         String str = IOUtils.toString(input,"utf-8");//问题所在之处
         System.out.println(str);
     }
 }

图2 项目目录结构

3、问题解决过程:

①一开始通过IDEA以正常方式导入,目录结构如图1所示,仍旧一样,未能解决,此方法行不通

②在IDEA中Tomcat 9.0.0.M16,中加入commons-io-2.5.jar(此jar包不在Tomcat的lib文件夹中),如图三所示,还是不行。

图三

③干脆把commons-io-2.5.jar拷贝到Tomcat的lib文件夹中,再在IDEA中导入,结果解决了,目录结构如图四所示。

至于为什么要把commons-io-2.5.jar拷贝到Tomcat的lib文件夹下,还有望大神们解答。

图4 解决后的目录结构

时间: 2024-10-12 19:30:41

Tomcat中使用commons-io-2.5发生的错误java.lang.ClassNotFoundException: org.apache.commons.io.IOUtils的相关文章

【转】用JSON报的一个错误java.lang.ClassNotFoundException: org.apache.commons.lang.exception.NestableRuntimeExcept

来源:http://blog.csdn.net/eilent/article/details/6927700 出现错误的原因是因为jar包导入不全. 今天自己写了一个JSON的例子,可以一调用就出了问题,报下面这个异常: java.lang.ClassNotFoundException: org.apache.commons.lang.exception.NestableRuntimeException 上网上搜了一下才知道原来在使用JSON的使用的时候,不光要导入JSON这个包,同时还要导入另

Caused by: java.lang.ClassNotFoundException: org.apache.commons.io.FileUtils

1.错误描述 警告: Could not create JarEntryRevision for [jar:file:/D:/MyEclipse/apache-tomcat-7.0.53/webapps/FirstSSH/WEB-INF/lib/struts2-core-2.3.16.3.jar]! java.lang.NoClassDefFoundError: org/apache/commons/io/FileUtils at com.opensymphony.xwork2.util.fs.

ssh整合启动tomcat报java.lang.ClassNotFoundException: org.apache.commons.lang.xwork.StringUtils

今天搭建了一个ssh项目环境,整合后,访问项目首页,登录不进去,控制台报错,后来调试代码后,在获取数据库数据后,返回到action时,又进入了action导致死循环,其实这里是两个问题,控制台报错如下: 2015-4-27 20:57:56 org.apache.catalina.core.StandardWrapperValve invoke严重: Servlet.service() for servlet default threw exceptionjava.lang.ClassNotFo

java.lang.ClassNotFoundException: org.apache.commons.dbcp.BasicDataSource解决方法

java.lang.ClassNotFoundException: org.apache.commons.dbcp.BasicDataSource解决方法 只需把这三个commons-pool.jar.commons-dbcp-1.2.2.jar和commons-collections-3.2.jar包加入到lib里即可解决.这三个包在你本地的tomcat下的lib里,直接buildpath导入就行了,不过有时导包不一定好使,是因为工程lib下的包跟tomcat下的包重复了,导致异常错误如: o

java.lang.ClassNotFoundException: org.apache.commons.dbutils.QueryRunner

七月 28, 2017 11:06:33 下午 org.apache.catalina.core.StandardWrapperValve invoke严重: Servlet.service() for servlet [com.itheima.transfer.web.TransferServlet] in context with path [/WEB19] threw exception [Servlet execution threw an exception] with root ca

Caused by: java.lang.ClassNotFoundException: org.apache.commons.fileupload.RequestContext

1.错误描述 usage: java org.apache.catalina.startup.Catalina [ -config {pathname} ] [ -nonaming ] { -help | start | stop } 2014-7-10 23:23:53 org.apache.catalina.core.AprLifecycleListener init 信息: Loaded APR based Apache Tomcat Native library 1.1.29 using

Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory

1.错误描述 2014-7-12 0:38:57 org.apache.catalina.core.ApplicationContext log 信息: No Spring WebApplicationInitializer types detected on classpath 2014-7-12 0:38:57 org.apache.catalina.core.StandardContext listenerStart 严重: Exception sending context initia

Hadoop java.lang.ClassNotFoundException: org.apache.commons.lang3.StringUtils

commons-lang3-3.3.2.jar 学习好友推荐案例的时候,提交运行时报错找不到StringUtils java.lang.ClassNotFoundException: org.apache.commons.lang3.StringUtils [root@node01 ~]# hadoop jar MyFOF.jar com.sxt.hadoop.mr.fof.MyFOF 19/03/30 00:25:37 WARN mapreduce.JobResourceUploader: H

Caused by: java.lang.ClassNotFoundException: org.apache.commons.lang3.StringUtils

1.错误描述 2014-7-10 23:12:23 org.apache.catalina.core.StandardContext filterStart 严重: Exception starting filter struts2 java.lang.NoClassDefFoundError: org/apache/commons/lang3/StringUtils at com.opensymphony.xwork2.config.providers.XmlConfigurationProv