Eclipse Maven Spring:当我尝试运行As Server(Tomcat 7)时出现服务器错误 [英] Eclipse Maven Spring: Server Error when I try to Run As Server (Tomcat 7)

查看:198
本文介绍了Eclipse Maven Spring:当我尝试运行As Server(Tomcat 7)时出现服务器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 Spring MVC 框架和 Maven 的Java项目作为其构建系统。我希望使用的主IDE是用于Java EE的 Eclipse 。我正在为我的应用程序使用标准的Maven项目结构:源代码位于 src / main / java 中,应用程序的资源位于 src / main /资源和与Web容器相关的代码位于 src / main / webapp 中。在 src / main / webapp / WEB-INF 中,我有一个 web.xml 文件,用于配置我的服务器和多个用于与Spring相关的文件的文件夹,例如上下文XML文件和视图。这些Spring文件在web.xml中合法链接。

I have a Java project using the Spring MVC framework and Maven as its build system. The primary IDE I wish to use is Eclipse for Java EE. I am using a standard Maven project structure for my application: source code is in src/main/java, resources for the application are in src/main/resources and code related to the web container are in src/main/webapp. In src/main/webapp/WEB-INF, I have a web.xml file for configuring my server and multiple folders for Spring-related files, such as context XML files and views. These Spring files are linked to legally in web.xml.

当我尝试使用 Maven-Tomcat7-Plugin 我的项目成功启动,我可以查看我的网页,看到我的REST控制器没有问题。

When I try to run the project using the Maven-Tomcat7-Plugin (via the mvn tomcat7:run-war goal), my project launches successfully and I am able to view my web pages and see my REST controller in action without issue.

但是,当我尝试在Eclipse中运行该项目时,使用其运行方式服务器选项,它从不工作,我没有想法为什么不。我继续收到错误对话框标题服务器错误,并显示消息选择不能在任何服务器上运行。我已经配置了一个 Tomcat 7 服务器运行时合法在Eclipse中;我可以使用这个运行时没有任何问题,我的其他Java项目。我已尝试Google,Stackoverflow和博客建议在Eclipse服务器上工作的Eclipse Maven Spring项目的一切。我试图删除Eclipse项目,删除Eclipse工作区文件并重新导入项目(既作为一个Maven项目和一个常规的Java项目),但无济于事。我也尝试在项目方面中启用动态Web模块,并将Web目录设置为 src / main / webapp ,但也不会有用。

However, when I try to run the project in Eclipse, using its Run As Server option, it never works and I have no idea why not. I keep getting an error dialog box titles Server Error and with the message The selection cannot be run on any server. I have already configured a Tomcat 7 server runtime legally in Eclipse; I can use this runtime without any problem for my other Java projects. I have tried everything that Google, Stackoverflow and blogs suggest to get an Eclipse Maven Spring project working on an Eclipse server. I've tried to delete the Eclipse project, delete the Eclipse-workspace files and reimport the project (both as a Maven project and as a regular Java project), but to no avail. I've also tried enabling the Dynamic Web Module in the Project Facets and setting the web directory to src/main/webapp, but also to no avail.

我很困惑;我以前曾在Eclipse中使用过Tomcat服务器,但它并不适用于这个特定的Spring项目,即使它使用Maven在Tomcat上部署正常。有人有什么想法可能会出错吗?我忘记了一个故障排除步骤吗?我的项目设置有什么问题与Eclipse在Web Server项目中所期望的冲突吗?感谢提前。

I'm baffled; I've worked with Tomcat servers in Eclipse many times before but it is just not working for this specific Spring project, even though it deploys just fine on Tomcat using Maven. Does anyone have any idea what might be going wrong? Have I forgotten a trouble-shooting step? Is there something wrong with my project setup that is conflicting with what Eclipse expects in a Web Server project? Thanks in advance.

推荐答案

我想我想出来了。 Eclipse的动态Web模块3.1版可能会出现错误。我的项目是使用这个版本导入的,因为我在我的pom.xml中使用了javax.servlet-api版本3.1。当我将版本更改为3.0版本时,我现在可以将其作为服务器运行。

I think I figured it out. There may be a bug in Eclipse's Dynamic Web Module, version 3.1. My project was being imported using this version because I am using version 3.1 of javax.servlet-api in my pom.xml. When I changed the version down to version 3.0, I am now able to run it as a server.

基本上,为了做到这一点,我不得不进入 .settings / org.eclipse.wst.common.project.facet.core.xml 并更改< installed facet =jst.web版本=3.1/> 标签为< installed facet =jst.webversion =3.0/>

Basically, to do this change, I had to go into the .settings/org.eclipse.wst.common.project.facet.core.xml and change the <installed facet="jst.web" version="3.1"/> tag to instead be <installed facet="jst.web" version="3.0"/>.

使用Eclipse发布错误的时间...

Time to file a bug with Eclipse...

这篇关于Eclipse Maven Spring:当我尝试运行As Server(Tomcat 7)时出现服务器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆