我不想在 WEB-INF/lib 文件夹中使用某个 jar,而是想在 WEB-INF/classes 文件夹中使用它的源代码(相同的目录结构和所有内容),这样我就可以修改它的类了。
然而,删除原始 jar 并将相应目录上传到 WEB-INF/classes 后(重新)启动我的 tomcat 会出现以下错误:
SEVERE: Error configuring application listener of class no.something.something1.http.LifecycleListener
java.lang.ClassNotFoundException: no.something.something1.http.LifecycleListener
我确信目录路径与 jar 内的路径相同。另外,我之前曾尝试在该 Web 应用程序中使用 WEB-INF 文件夹中的类,但由于某种原因,tomcat 也无法加载它们。
有谁知道我如何解决此错误?
Instead of using a certain jar in my WEB-INF/lib folder, I want to use its source code (same directory structure and everything) in my WEB-INF/classes folder, so that I may be able to modify its classes more story.
Yet (re)starting my tomcat after deleting the original jar and uploading the corresponding directory into WEB-INF/classes gives me the following error:
SEVERE: Error configuring application listener of class no.something.something1.http.LifecycleListener
java.lang.ClassNotFoundException: no.something.something1.http.LifecycleListener
I am certain that the directory path is the same as the one inside the jar. Also, I have previously tried using classes in my WEB-INF folder for this web application, and tomcat has also been unable to load them, for some reason.
Does anyone know how I go about troubleshooting this error?
发布评论
评论(2)
Tomcat 只能加载
.class
文件,它不知道如何处理原始源代码文件。无论如何,Tomcat 不会对.class
文件进行热加载。无论哪种方式,在重新编译应用程序或服务器后,您都必须重新启动应用程序或服务器,将它们打包为.war
并不是什么太大的负担一旦你自动化它。如果您花时间自动构建和部署适当的 .war,您只需重建 .war,它就会自动取消部署并重新部署应用程序本身,这比重新启动整个服务器快很多倍。
你无法按照你想要做的方式去做你想要做的事情。像 JRebel 这样的工具可以解决这些问题,但我认为它们并不像它们的营销听起来那么有用。
Tomcat can only load
.class
files, it doesn't know what to do with raw source code files. Tomcat doesn't do hot loading of.class
files like that anyway. You would have to restart the application or server after you recompiled them either way, packaging them as a.war
isn't that much of a burden either way once you automate it.If you take the time to automate the build and deployment of a proper .war you can just rebuild the .war and it will automagically undeploy and redeploy the application itself, which is many times faster than restarting the entire server.
You can't do what you are trying to do the way you are trying to do it. Tools like JRebel address these issues, but I don't find them as useful as their marketing makes them sound.
您可以根据需要使用嵌入式 tomcat(或嵌入式 jetty)来映射应用程序的目录结构。如果您的应用程序中需要一些 JNDI 资源,那么可能需要进行一些修改,但仍然值得这样做。
这是一个示例
You could use embedded tomcat (or embedded jetty) to map directory structure of the application as you like. It probably will require some tinkering if you need some JNDI resources within your application but still worth the trouble.
Here's an example