无法将我的 Spring Web 项目部署到 Eclipse 内部 tomcat 服务器。(tomcat 启动时出现 java.lang.ClassNotFoundException)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21854404/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Unable to deploy my spring web project to eclipse internal tomcat server.(java.lang.ClassNotFoundException on tomcat startup)
提问by Meysam Feghhi
when I use an external tomcat everything is just fine. but I need to deploy my project on internal eclipse tomcat server in order to be able to use DCEVM class hot swapping. When I try to start tomcat server from within eclipse it says it is not able to find one of my service classes I mentioned in my spring security configuration file as a bean. I also tried to add the project to tomcat class path but it did not solve my problem.
当我使用外部 tomcat 时,一切都很好。但我需要在内部 eclipse tomcat 服务器上部署我的项目,以便能够使用 DCEVM 类热插拔。当我尝试从 eclipse 中启动 tomcat 服务器时,它说它无法找到我在 spring 安全配置文件中提到的作为 bean 的服务类之一。我也尝试将项目添加到 tomcat 类路径,但它没有解决我的问题。
UPDATE
更新
I found out the problem is because when I deploy my web project to eclipse tomcat server, no .class is copied to:
我发现问题是因为当我将我的 web 项目部署到 eclipse tomcat 服务器时,没有 .class 被复制到:
C:\Users\Meysam\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\villapweb\WEB-INF\classes
in fact, this folder contains my src/java/main package structure but no .class is copied in it.
事实上,这个文件夹包含我的 src/java/main 包结构,但没有复制 .class 。
lib folder is fine though (e.g. all dependencies of maven and other stuff copies in the path it is supposed to)
lib 文件夹虽然很好(例如,maven 的所有依赖项和它应该复制的路径中的其他东西)
I think there might be something wrong with m2e-wtp plugin. I dont know what!
我认为 m2e-wtp 插件可能有问题。我不知道什么!
I am using eclipse 4.3 BTW.
我正在使用 Eclipse 4.3 顺便说一句。
SOLVED
解决了
I Solved this issue following these steps:
我按照以下步骤解决了这个问题:
- right click on project in eclipse > properties > project facets
- in the right panel select runtimes and select your target server. Apply and ok.
- in the server modules list right click on project module and click clean module work directory
- right click on the server itself and you can clean both server and tomcat work directory one after another
- if that didn't work, try project > clean and also toggle "build automatically" option under project menu item.
- 右键单击eclipse中的项目>属性>项目方面
- 在右侧面板中选择运行时并选择您的目标服务器。申请就OK了。
- 在服务器模块列表中右键单击项目模块,然后单击清理模块工作目录
- 右键单击服务器本身,您可以一个接一个地清理服务器和tomcat工作目录
- 如果这不起作用,请尝试 project > clean 并在项目菜单项下切换“自动构建”选项。
Thats it. tomcat now copies all .class files to the target server and you see no ClassNotFound exception as tomcat starts up.
就是这样。tomcat 现在将所有 .class 文件复制到目标服务器,并且在 tomcat 启动时您看不到 ClassNotFound 异常。
回答by Soman Dubey
[Copied to answer section]
[复制到答案部分]
I Solved this issue following these steps:
我按照以下步骤解决了这个问题:
- right click on project in eclipse > properties > project facets
- in the right panel select runtimes and select your target server. Apply and ok.
- in the server modules list
- right click on project module and click clean module work directory right click on the server itself and you can clean both server and tomcat work directory one after another
- if that didn't work, try project > clean and also toggle "build automatically" option under project
- 右键单击eclipse中的项目>属性>项目方面
- 在右侧面板中选择运行时并选择您的目标服务器。申请就OK了。
- 在服务器模块列表中
- 右键单击项目模块并单击清理模块工作目录右键单击服务器本身,您可以一个接一个清理服务器和tomcat工作目录
- 如果这不起作用,请尝试 project > clean 并切换项目下的“自动构建”选项
Thats it. tomcat now copies all .class files to the target server and you see no ClassNotFound exception as tomcat starts up.
就是这样。tomcat 现在将所有 .class 文件复制到目标服务器,并且在 tomcat 启动时您看不到 ClassNotFound 异常。
回答by inor
I had almost the same problem - one of my projects did not make it to the deployment area (its jar). What i did is 1) remove the appliction from tomcat 2) clean tomcat work directory 3) most important: project - clean - all. Then i added the application again and... problem solved
我遇到了几乎同样的问题 - 我的一个项目没有进入部署区域(它的 jar)。我所做的是 1) 从 tomcat 中删除应用程序 2) 清理 tomcat 工作目录 3) 最重要的是:project - clean - all。然后我再次添加了应用程序......问题解决了
回答by Willie Zayas
I've followed the steps on the answer but It still wouldn't work for me, so, besides doing these steps once, I've found that doing a refresh on the target after doing a clean installautomatically triggers the "Republish" status on the server, so when the server is executed all changes on the compiled classes (new classes and changes to existing ones) are then copied to wtpwebapps when the server is started.
我已经按照答案中的步骤操作,但它仍然对我不起作用,因此,除了执行一次这些步骤之外,我发现在执行 a 后对目标进行刷新会clean install自动触发“重新发布”状态服务器,因此当服务器被执行时,所有对编译类的更改(新类和对现有类的更改)都会在服务器启动时复制到 wtpwebapps。
回答by Foontik
I had the same problem in Web Dynamic project converted to Maven project.
我在转换为 Maven 项目的 Web 动态项目中遇到了同样的问题。
I found error in properties->Deployment Assembly->right panel.
There was source=src folderand deploy path=WEB-INF/classes. Classes couldn't be found by Eclipse.
我在属性-> 部署程序集-> 右侧面板中发现错误。有source=src folder和deploy path=WEB-INF/classes。Eclipse 找不到类。
Changed to source=target/classes.
改为source=target/classes.

