Errors in using commons-io-2.5 in Tomcat java. lang. ClassNotFoundException: org. apache. commons. io. IOUtils,
Keywords: IntelliJ IDEA, Tomcat, commons-io-2.5.jar, java. lang. ClassNotFoundException: org. apache. commons. io. IOUtils
1. error message
Figure 1 error message during logon
// Tomcat Localhost Log information 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 File Content
@ 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 where the problem is located. out. println (str );}}
Figure 2 project directory structure
3. Problem Solving Process:
① At the beginning, I imported data through IDEA in a normal way. The directory structure 1 is still the same and cannot be resolved. This method does not work.
② In IDEA Tomcat 9.0.0.M16, add the commons-io-2.5.jar (this jar package is not in the lib folder of Tomcat), three, or not.
Figure 3
③ Simply copy the commons-io-2.5.jar to the lib folder of Tomcat, and then import it in IDEA. The result is solved, and the directory structure is shown in table 4.
As for why to copy the commons-io-2.5.jar to the Tomcat lib folder, we hope you can answer.
Figure 4 directory structure after solution