Error java.lang.ClassNotFoundException:org.apache.commons.io.IOUtils using commons-io-2.5 in Tomcat

Source: Internet
Author: User

Key words: IntelliJ idea, Tomcat, Commons-io-2.5.jar, java.lang.ClassNotFoundException:org.apache.commons.io.IOUtils

1. Error message

Figure 1 Error message when you run a logon

//Tomcat Localhost Log InformationOrg.apache.catalina.core.StandardWrapperValve.invoke Servlet.service () forservlet [servlet] in context with path [] threw exception [servlet execution threw a 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 File contents

@WebServlet (name = "Servlet", Urlpatterns = "/servlet") public class Servlet extends httpservlet {     protected V OID 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");//Where the problem is System.out.println (str);} }     

Figure 2 Project directory structure

3, Problem solving process:

① started with idea in normal import, directory structure 1, still the same, not resolved, this method is not feasible

② in Idea Tomcat 9.0.0.m16, add Commons-io-2.5.jar (this jar package is not in Tomcat's Lib folder), three, or not.

Might

③ simply copy the Commons-io-2.5.jar into the Tomcat Lib folder, and then import it in idea, the result is resolved, the directory structure is shown in four.

As for why the Commons-io-2.5.jar copy to the Tomcat Lib folder, but also hope that the great God answers.

Figure 4 Post-resolution directory structure

Error java.lang.ClassNotFoundException:org.apache.commons.io.IOUtils using commons-io-2.5 in Tomcat

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.