How do I update my Maven project to work in Eclipse?
Author: Deron Eriksson
Description: This tutorial describes how to update a project with the maven eclipse:eclipse goal.
Tutorial created using:
Windows Vista || JDK 1.6.0_04 || Eclipse Web Tools Platform 2.0.1 (Eclipse 3.3.1)
In other tutorials, we created a maven project called "mytest" and imported it into Eclipse. After importing the project, it had build path issues. This is because the project uses junit, but the project's .classpath file doesn't contain an entry for the junit dependency yet. The mytest project is shown here with the red x icons indicating that there are problems with the project. There is actually a very easy solution for this. The mavenSW "eclipse:eclipse" goal will download any necessary dependencies and will update our project's .classpath to include these dependencies. The maven command using the eclipse:eclipse goal would be mvn eclipse:eclipse The maven eclipseSW plugin requires an M2_REPO classpathW variable. This variable needs to point to the local maven repository. On my machine, this is located at C:\dev\m2repo. I went to Window → Preferences and JavaSW → Build Path → Classpath Variables. I clicked the New button and created the M2_REPO classpath variable and pointed it to my local maven repository. The new M2_REPO classpath variable can be seen here. Now, I'll create an External Tool configuration so that I can run the maven eclipse:eclipse goal in Eclipse. I'll create the configuration with the following features.
The Name can be anything that you'd like. I call mine "mvn eclipse~eclipse". I would have used a : instead of a ~ but Eclipse doesn't allow colons in the name field. The Location points to mvn.bat (maven). The Working Directory is an Eclipse variable that specifies the currently selected project's location in the file system. The Arguments field specifies "eclipse:eclipse", the maven goal that we'd like to execute. After creating the External Tool configuration, I went back to my Navigator view and selected the "mytest" project. I then went to the External Tool Dialog and selected the "mvn eclipse~eclipse" configuration and clicked Run. After the eclipse:eclipse goal ran successfully, I refreshed the "mytest" project. After refreshing, all the project errors disappeared. This is because the junit dependency was added to the project .classpath file. (Continued on page 2) Related Tutorials:
|