eclipse/tomcat:部署不再工作(ClassNotFoundException)

发布于 2024-11-05 13:33:58 字数 1703 浏览 1 评论 0原文

我正在 Linux Ubuntu Natty Narwhal 中运行 Eclipse Helios Service Release 1 和 Tomcat 7.0.12。

我一直很高兴地重新部署我的网络应用程序,直到它毫无理由地停止工作。显示以下异常:

SEVERE: Allocate exception for servlet Index
java.lang.ClassNotFoundException: obliquid.servlet.Index
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1676)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1521)
  • 服务器选项卡中,我有“Tomcat v7.0服务器位于本地主机[已启动,同步]
  • 显示为Tomcat v7.0服务器的子项
  • 我的项目在属性,Java构建路径中 ,源我有 Project/src 源文件夹
  • 在属性、Web 部署程序集中,我有以下映射:/WebContent -> / >, /src -> /WEB-INF/classes/test -> /build/classes
  • 我的src 目录包含 obliquid/servlet/Index.java 中的 Servlet
  • 我已经尝试单击清理模块工作目录...>发布
  • 我尝试停止并启动服务器从 Eclipse Servers 选项卡中

我还应该检查什么?

更新 尽管现在我正在处理新项目,但我回来检查旧项目,我认为它现在正在工作。我无法找到发生了什么。

但是今天在新项目中,我遇到了没有明显原因的 404 错误,我发现右键单击 Tomcat 服务器并选择“清理...”可能很有用。也许这会有所帮助。

选择“清理...”表示:“清理将放弃所有发布状态并从头开始重新发布。您确定要清理所有已发布的资源吗?”。选择是,我解决了问题

更新2它在新项目上再次发生。 404 错误,这次它们不会消失。

Stop -> Clean... -> Start (404)
Stop -> Clean Tomcat Work Directory... -> Start (404)
Stop -> Clean Tomcat Work Directory... -> Clean... -> Start (404)
Stop -> Remove on the application ->  Clean... -> Run As -> Run on Server -> (404)  
Exit Eclipse, Start Eclipse
Start the server -> (404)

UPDATE 3 事实证明,这次我只是没有注意到启动过程中由侦听器类引起的异常。解决问题后,成功了。我想我应该在凌晨 3 点停止工作。

I'm running Eclipse Helios Service Release 1, with Tomcat 7.0.12 in Linux Ubuntu Natty Narwhal.

I've been happily hot re-deploying my webapp until it stopped working for apparently no reason. The following exception is displayed:

SEVERE: Allocate exception for servlet Index
java.lang.ClassNotFoundException: obliquid.servlet.Index
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1676)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1521)
  • In Servers tab I've "Tomcat v7.0 Server at localhost [Started,Synchronized]
  • My project appears as a child of Tomcat v7.0 Server
  • In Properties, Java Build Path, Source I've Project/src Source folder
  • In Properties, Web Deployment Assembly, I've the following mappings: /WebContent -> /, /src -> /WEB-INF/classes, /test -> /build/classes
  • My src directory contains a Servlet in obliquid/servlet/Index.java
  • I tried already to click on Clean Module Work Directory... and Publish
  • I tried to stop and start the Server from within Eclipse Servers tab

What else should I check? Thank you.

UPDATE Despite now I'm working with the new project, I came back to check the old one, and mysteriously now it's working. I think I won't be able to find what has happened.

However today with the new project, I had 404 errors with no apparent reason and I found out that right clicking on the Tomcat server and selecting "Clean..." can be useful. Maybe it could have helped.

Selecting "Clean..." says: "Clean will discard all publish state and republish from scratch. Are you sure you want to clean all published resources?". Selecting yes, I solved the problem

UPDATE 2 It happened again on the new project. 404 errors, this time they don't go away.

Stop -> Clean... -> Start (404)
Stop -> Clean Tomcat Work Directory... -> Start (404)
Stop -> Clean Tomcat Work Directory... -> Clean... -> Start (404)
Stop -> Remove on the application ->  Clean... -> Run As -> Run on Server -> (404)  
Exit Eclipse, Start Eclipse
Start the server -> (404)

UPDATE 3 It turned out that this time I just didn't notice an exception caused by a listener-class during startup. After solving the problem, it worked. Guess I should stop working at 3 AM.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(10

南街九尾狐 2024-11-12 13:33:58

在 Tomcat 6 和 Eclipse Ganymede 上,我发现以下链像魅力一样工作:

1 stop server

2 project ->清理

3 项目构建(我禁用了自动构建)

4 删除服务器

5 删除服务器文件夹

6 重新启动 Eclipse

7 创建新服务器,添加项目并启动:)

需要一些时间,但效果很好。我的问题是一个令人恼火的监听器启动问题,但这似乎是类似的问题:tomcat 的一个属性。顺便说一句:现在我也是 Glassfish 的忠实粉丝。

While on Tomcat 6 and Eclipse Ganymede I found out the following chain to work like charm:

1 stop server

2 project -> clean

3 project build (I had automatic build disabled)

4 delete server

5 delete Servers folder

6 restart Eclipse

7 create new server, add project and start :)

takes some time but worked like charm. My problem was a irritating Listener start problem, but this seems to be something similar: a property at tomcat. Btw: nowadays I am also a big Glassfish fan.

烏雲後面有陽光 2024-11-12 13:33:58

我发现此过程很有用:

  • 单击服务器选项卡,然后停止正在使用的服务器(如果正在运行)
  • 再次右键单击服务器并选择清理...
  • 再次右键单击并选择清理 Tomcat 工作目录...

希望 ClassNotFoundException 现在应该消失了。

还有一次,我在服务器启动时启动的类遇到了问题,侦听器类 (ServletContextListener) 中出现异常。当 ServletContextListener 在启动期间引发异常时,应用程序部署将中止,因此会出现 404 错误。在这种情况下,解决导致异常的问题,使应用程序再次运行。

编辑:这个较短的程序在大多数情况下对我来说都有效,但今天不起作用,我必须遵循 Mico 的扩展程序。我的建议是,如果您遇到类似的问题,请首先尝试这个较短的过程。如果问题仍然存在,请尝试使用 Mico。

I found that this procedure is useful:

  • Click on Servers tab and Stop the server in use if it's running
  • Right click on the server again and select Clean...
  • Right click again and select Clean Tomcat Work Directory...

Hopefully the ClassNotFoundException should be gone now.

Another time I had a problem with a class launched at server startup, an exception in a listener class (ServletContextListener). When a ServletContextListener raises an exception during startup the application deployment is aborted, hence the 404 errors. In that case fixing the problem that caused the exception, made the application working again.

EDIT: This shorter procedure worked for me most of the times, but today didn't work and I had to follow Mico's extended procedure. My suggestion is, if you have a similar problem, first try this shorter procedure. If the problem persists, try with Mico's.

穿越时光隧道 2024-11-12 13:33:58

我建议您停止并重新启动 Tomcat 服务器。热部署并不能永远有效;有一些问题会导致您在几次重新部署后必须重新启动。

I'd recommend that you stop and start the Tomcat server again. Hot deploy does not work forever; there are some issues that will cause you to have to restart after a few redeploys.

走过海棠暮 2024-11-12 13:33:58

我想知道当我看到带有 +25已接受答案时,它真的准确吗?

首先,如果您要删除服务器,那么清理它有什么意义呢?这会不必要地占用您的时间并且您不会获得任何有用的东西。

所以我想说,只需5、6、7步就可以发挥作用

5 删除 Servers 文件夹

6 重新启动 Eclipse

7 创建新服务器,添加项目并启动

I wonder when I see the accepted answer with +25 is it really accurate?

First if you are going to delete the server then whats the point in cleaning it? It will take your time unnecessarily and nothing useful will you gain.

So i will say just 5, 6, 7 steps should do the magic

5 delete Servers folder

6 restart Eclipse

7 create new server, add project and start

追星践月 2024-11-12 13:33:58

这可能是我在 承认 2 011。对我来说,这听起来像是一个类加载器问题。

背后的理论:

  • Java 不仅使用类的类型,还使用加载该类的类加载器来识别实例的类型。这意味着简单的操作可能会失败,例如

    A 类 a1 = 新 a1;
    ClassA a2 = SomeOtherClass.giveMeInstanceOfA();
    a1 = a2;

如果 SomeOtherClass 使用不同的类加载器,则此示例将失败,因为 Java 会说它们不相同。

  • 演讲者还提到,一些服务器默认使用大约 45 个不同的类加载器。

这在实践中意味着什么:

您将 Web 应用程序部署到服务器,一切都运行良好。服务器缓存了类以及加载它们所需的一切。现在您进行了热部署,服务器可能会使用新的(或不同的)类加载器加载新类。这就是它开始变得危险的地方,因为从现在开始,内存中有两个不同的类,它们应该是相同的。像强制转换 (ClassA a = (ClassA) new ClassA()) 这样的简单操作失败,找不到类中的 new 方法(因为服务器采用没有此方法的缓存版本),....

这是我重新启动的点服务器,清理工作目录(以摆脱缓存的版本)并开始将热部署视为至关重要的事情。

如果可以尝试 Mikkos procedere 并且这可以解决问题,那么这个解释可以帮助您理解原因。

我知道这并不能解决您的问题,但可以给您一些可能发生的情况的提示。

This could be something I learned on con-fess 2011. For me this sounds like a classloader problem.

The theory behind:

  • Java does not only use the type of the class but also the classloader which loaded it to identify the type of an instance. This means a simle operation could fail, e.g.

    ClassA a1 = new a1;
    ClassA a2 = SomeOtherClass.giveMeInstanceOfA();
    a1 = a2;

This example would fail if SomeOtherClass uses a different classloader because Java would say that they are not the same.

  • The speaker also mentioned that some servers use per default about 45 different classloaders.

What does this mean in practice:

You deploy your webapp to the server, everything runs fine. The server caches the classes and everything he needs to load them somewhere. Now you make a hot deploymen and the server may loads new classes with a new (or different) classloader. This is the point where it starts to become dangerous because from now on you have two different classes in the memory which should be the same. Simple operations like casts (ClassA a = (ClassA) new ClassA()) fail, new Methods within the class are not found (because the server takes a cached version without this method),....

This is the point where I restart the server, clean the working directory (to get rid of the cached versions) and start thinking about hot deployment as critical thing.

If it is possible to try Mikkos procedere and this solves the problem this explanation could help you understand why.

I know this does not solve your problem but could give you some hints what maybe could have happened.

書生途 2024-11-12 13:33:58

说到Tomcat的热部署,你确实会遇到各种各样的问题,其中最轻的就是内存泄漏,这就是为什么你必须重新启动应用程序。我建议尝试 JRebel 来实现“进行并保存任何更改,然后刷新浏览器并立即查看更改”的快速周转。您可以找到 JRebel 实践实验室,其中展示了如何将其与 Tomcat 和 Eclipse 一起使用。 http://www.javapassion.com/rebels/jrebel_basics/

Speaking of hot deployment of Tomcat, you would indeed experience various problems, the least of which is memory leak, which is why you would have to restart the application. I would recommend to try JRebel for fast turnaround of "make and save any changes and then refresh the browser and see the changes immediately". You can find the JRebel hands-on lab, which shows how to use it with Tomcat and Eclipse. http://www.javapassion.com/rebels/jrebel_basics/

怂人 2024-11-12 13:33:58

我获得了一些新的编程经验,我不再渴望 Eclipse + Tomcat 组合。这里有几种方法可以帮助您摆脱使用该组合的需要:

首先,不要一起使用它们!

  • 您可以使用其他可用的IDE,例如IntellijIdea(不是免费的,但值得投资)有一个特性,当您调试Java代码时,您可以动态更改代码并逐一编译Java文件,然后它会建议您是否要在服务器上更新它。几乎不需要重新启动(当然它有时会丢失,但主要是它可以工作)。

  • 使用独立的 tomcat 服务器,而不是 Eclipse/IDE 中的服务器。第一个技巧仅在您调试外部服务器时起作用,而在 IDE 中不起作用。第二个技巧是:如果您碰巧只更改 jsp 或 html 内容,则可以使用 unix cp 或 windows copy 命令手动将这些文件复制到 tomcat 的 webapp 文件夹中的正确位置,并且如果您碰巧长时间在同一个文件夹中开发文件,您可以根据需要多次复制文件夹内容(例如 myFolder/*.jsp),并且根本不需要重新启动。当您触摸或编辑并保存 webapps 文件夹中的 web.xml 文件时,更改就会可见,然后刷新浏览器上的可见页面。使用 CTRL+F5 进行硬刷新可能是最好的方法。

感谢@Verdan 的评论,否则我不会再回来回答。

I have gained some new experience on programming and I am not anymore starving on Eclipse + Tomcat combination. Several ways here can help you out of the need of the usage of that combination:

First of all, don't use them together!

  • You can use other available IDEs, e.g. IntellijIdea (that is not free, but is worth of investing) has an property that when you debug a Java code, you can change code on fly and compile the Java files one by one and then it suggests if you'll want to have it updated on server. No restart needed almost never (of course it sometimes gets lost, but mainly it works).

  • Use standalone tomcat server, not the one inside Eclipse / your IDE. That first trick works only when you debug external server, nothing inside IDE. There comes the second tip: if you happen to change only jsp or html content, those files can be copied to the right place inside tomcat's webapp folder manually with unix cp or windows copy command and if you happen to develop files in same foulder long time, you can copy the folder content (e.g. myFolder/*.jsp) as many times as you wish and no restart is needed at all. The changes come visible when you touch or edit&save the web.xml file inside the webapps folder and then after that with refreshing the visible page on browser. Probably hard refresh with CTRL+F5 is the best way.

Thanks to @Verdan about his comment, otherwise I wouldn't have came back to answer again.

零時差 2024-11-12 13:33:58

我能够通过禁用 Maven 性质来解决此问题(右键单击项目>> Maven>> 禁用 Maven 性质)。然后重新启用它(右键单击项目>>配置>>转换为maven项目)。我已经尝试了上面所有其他的提示和技巧,但这是最终奏效的。

I was able to solve this by disabling the maven nature (right click on project >> maven >> disable maven nature). Then re-enabling it (right click on project >> configure >> convert to maven project). I had tried all of the other tips and tricks above, but this is the one that finally worked.

赠我空喜 2024-11-12 13:33:58

我遇到了同样的问题 - 尝试了上述所有方法,当我尝试启动服务器时,Eclipse 总是冻结,即使我删除了所有服务器配置并使用新下载的 tomcat 实例创建了一个新配置。不管怎样,直到我搬到一个新的工作区,重新导入项目并创建一个新服务器之前,问题才得到解决。对我来说,这似乎是一个 Eclipse bug...所以如果没有其他办法,这就是要走的路...

I was running into the same problem - tried all of the above, Eclipse always freezed when i tried to start the server, even after i deleted all the server configs and created a new one with a freshly downloaded tomcat instance. Anyways, problem wasnt solved until i moved to a new workspace, reimported the projects and created a new server. Seems like an Eclipse bug to me...So in case nothing else works, this is the way to go...

感情旳空白 2024-11-12 13:33:58

我目前正在努力解决同样的问题,但这里提到的任何内容都不能帮助我。无论如何,我发现如果我:

  1. 在 eclipse 中停止服务器 在
  2. 其他地方运行 tomcat (在我的例子中是 xamp 发行版)
  3. 停止当前运行的 tomcat
  4. 在 eclipse 中启动 tomcat

一切正常,当然,直到我更改代码中的某些内容并尝试测试它再次。

I'm currently struggling with the same problem, but nothing mentioned here does not help me. Anyway, I found out that if I:

  1. stop server in eclipse
  2. run tomcat elsewhere (in my case the xamp distribution)
  3. stop currently running tomcat
  4. start tomcat in eclipse

everything works just fine, of course until I change something in code and try to test it again.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文