1. In TERMINAL, navigate into your newly created maven webapp folder called “SpringGreetings”.
$ pwd /Users/altheaparker/Documents/workspace $ cd SpringGreetings
2. Generate Eclipse files by the command mvn eclipse:eclipse
$ mvn eclipse:eclipse
3. Open Eclipse and import the maven webapp project now.
In Eclipse, go into File -> Import… and select “General -> Existing Projects From Workspace”. Browse to your workspace and select the folder “SpringGreetings”. Click “Open”. Then leave all the defaults on the next screen and click “Finish”
Wow, that was easy. The project is in Eclipse! This is what it should look like:
The best thing that happened is that the build path was configured automatically. You can see this by right clicking on the project “SpringGreetings” and going into Java Build Path -> Libraries. The junit library is already there! Take a look at the Source tab now. It is configured to output source code to “SpringGreetings/target/classes”.
4. Change a dependency and clean Eclipse.
Now just for fun, we are going to change one of the dependency jars. Let’s go to http://www.mvnrepository.com and shop for a newer version of junit, say, version 4.8.1. Type in the search box “junit” and select “4.8.1″. See on the mvnrepository website there is this handy code to insert into your pom.xml file! Open your pom.xml file and replace the existing junit dependency code with this code you found on the website:
<dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.8.1</version> </dependency>
After changing the pom.xml file, clean eclipse by entering the following in TERMINAL:
$ pwd /Users/altheaparker/Documents/workspace/SpringGreetings $ mvn eclipse:clean eclipse:eclipse
Now back in Eclipse, hit F5 or right click on the project and click “Refresh”. You see in “referenced libraries” or in the build path that the new jar is updated!