0
votes

I want to run the following sample code in Eclipse EE, NOT STS.

The guide is ehre: https://spring.io/guides/gs/rest-service/ Direct link to code is ehre: https://github.com/spring-guides/gs-rest-service/archive/master.zip

The following are the steps I am taking:

1) Extract gs-rest-service-master and copy the directory named "complete" into the worspace directory. 2) Using eclipse, "Import Existing Maven Projects" and select the "complete" directory.

The project looks messed up as there is no "Maven Dependencies" despite right clicking and doing a "Maven Install" results in success...

3) I try making it into a faceted Dynamic Web Project 3.0 with Java 1.7.

There are errors with Application.java and GreetingController.java,

The import org.springframework cannot be resolved

Ideally I want to be able to run this in Tomcat, but I have no idea whats causing these errors. In "STS" it is very straightforward to get going, but I want to run in standard eclipse (EE) and not use STS.

What is the proper steps to take? I have been trying out enabling and disabling things but they all appear to have no effect. I dont understand why even the "Maven Dependencies" that are supposedly downloaded dont even show up.

How to have this project work with Tomcat?

3

3 Answers

2
votes

I did the following:

  • I downloaded the zip file
  • I uncompressed the zip file
  • I went in the ${PROJECT_HOME}/complete
  • I launched the command below :

    mvn eclipse:eclipse

  • I opened Kepler and imported the project by selecting the classical 'Import existing project..'
0
votes

I was able to replicate the issue in eclipse kepler. Initially, I went through all the steps mentioned without any issue. But then playing around with .classpath file, I removed the below snippet and then I found Maven dependencies were missing and the issues mentioned popped up. Somehow this snippet might not have been created in your project when imported.

Make sure you have this snippet in classpath for m2e plugin and do refresh by right-clicking on project:

<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
    <attributes>
        <attribute name="maven.pomderived" value="true"/>
    </attributes>
</classpathentry>

Reason why we need this is classpath entries with "maven.pomderived" attribute set to true are removed and recreated during project import and configuration update. Entries that do not have this attribute are copied as-is.

0
votes

After building project with maven and be sure it is working "preferred to do this step outside eclipse", then run this command before importing project to eclipse

mnv eclipse:eclipse

then import project as exist project, not maven project, then add maven nature to the project if you want

Edit1:

I just got that it is starter project so it is a jar project not war one so you will face issues to define it as dynamic web project, so to do it in easier way, generate WAR from the project import it in eclipse as WAR then add java classes, so you can integrate easily with eclipse web blugins.