I recently started developing a Spring MVC maven project. After I run mvn eclipse:eclipse
command from the run configurations all the maven dependencies are displayed outside the project and not under "Maven Dependencies" Hierarchy view. When I switch my project perspective to Java from Java EE then the dependencies are found under Referenced Libararies
.
My .project and .classpath metadata file contents.
Anybody got idea on how to display all the jars under the Maven Dependencies
view?
I thought, giving an answer might be better than writing comments.
The Maven Eclipse plugin
Assume you have the following project directory:
You now run a
mvn eclipse:eclipse
inside that directory to eclipsify it. This will create some meta files:The
.project
file will contain a comment line with the statementThe
.classpath
will have entries for the dependencies like these:Note that these entries are using an eclipse internal variable:
M2_REPO
, which points to your local maven repository. After all these entries are simple library entries. The same that you would get when adding a library to the build path.If you now import this via "Existing Projects into Workspace", you will exactly get the project that you described. Libraries are simple classpath entries. And - more important - it doesn't have the maven nature (it is missing the little "M" icon). That was mentioned in the
.project
file. Without the maven nature you do not have some useful and important features for this project.The Eclipse Maven plugin
So, let's repair that. Make a backup of the project directory first (in case of anything going wrong).
First step is to remove the project from eclipse, but not from the harddisk. So simply delete it in eclipse, but don't tick "Delete project contents on disk". You still want to have this project, don't you?
Step 2: Navigate to the project directory and delete any eclipse meta files (I already told you). Afterwards you have the same project directory as in the initial situation.
Step 3: Now you can import this project into eclipse with "Existing Maven Projects". Browse to the directory that contains your project (might be the workspace directory) and select your project.
You will notice afterwards that this project now has the maven nature. There is a little "M" icon at the project icon. Additionally, you will see all libraries under a "Maven Dependencies" node.
Why is that so? Let's have a look at the meta files again:
The
.project
file now also contains the following lines (among others):The
.classpath
now also has the following entry:And the M2E plugin now is doing the rest. Easy, isn't it?