java lang ClassNotFoundException listeners ContextListener
在运行tomcat源码中遇到的问题
在启动tomcat源码后,tomcat自带的几个项目都生效了,如docs,manage等等,但是examples模块始终无法访问,查看控制台日志后发现加载examples时,发生了错误。
one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
One or more listeners failed to start. Full details will be found in the appropriate container log file
Context [/examples] startup failed due to previous errors
根据提示的内容找到日志文件logs/localhost.yyyy-MM-dd.log,看到错误日志:
java.lang.ClassNotFoundException: listeners.ContextListener
...
java.lang.ClassNotFoundException: listeners.SessionListener
...
java.lang.ClassNotFoundException: async.AsyncStockContextListener
之后去源码中去找这几个类,发现确实存在,但是是在examples项目的WEB-INF的classes文件夹下,而且图标不对
因为报的异常是找不到类,但是类确实存在,只有一种可能,那就是没有加载进内存,在idea的maven项目中要将java文件编译,加载进内存需要将文件夹设置为Sources Root
设置完成后项目中的类就会编译,加载进内存。
重新启动tomcat源码,就发现可以访问examples类