ecbrodie
ecbrodie

Reputation: 11896

Eclipse Maven Spring: Server Error when I try to Run As Server (Tomcat 7)

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.

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.

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.

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.

Upvotes: 1

Views: 8300

Answers (1)

ecbrodie
ecbrodie

Reputation: 11896

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.

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"/>.

Time to file a bug with Eclipse...

Upvotes: 8

Related Questions