Maven root pom.xml marked as red when importing existing project into eclipse
Asked Answered
T

6

37

When importing existing maven project into eclipse my root pom.xml is marked red. when i select on the pom.xml the message reads :

Can't import project XYZ from an existing workspace folder

This only happens for the root pom.xml

Eclipse in use: Luna Service Release 2 (4.4.2) Maven Integration for Eclipse 1.5.2.20150413-2215

I have tested with number of different maven projects and in different workspaces.

Please note this worked before, I have been working on some tutorials and created number of Maven projects with same name and artifact Ids etc. I have deleted all the earlier projects, but could there still be some conflicts ?

any suggestions will help

Toy answered 2/5, 2015 at 8:30 Comment(10)
please check, if your M2_repo is pointing to the correct pathMacymad
Thanks, its point outside of my workspace to my home directory (mac) Where should it be pointing to normally?Toy
I found the .M2/repository in my home directory so i assume its pointing to the right locationToy
Not sure on Mac, ideally is should point to the location specified in settings.xmlMacymad
good point, what about settings.xml? this does not seem to exist on my machine, or at least it does not exist where eclipse is pointing to in preferences -> maven -> user settingsToy
in Windows it exists in c:\users\<username>\.m2, not sure on macMacymad
Thanks, so its seems like it follows similar structure, on my machine its not there, could this be causing this problem ? where can i get the settings.xml file?Toy
settings.xml, you can download from maven's site, but let me ask you one question, is maven installed on your system. if yes, it would surely have saved this file somewhere, just search your system.Macymad
That worked, i found that my settings.xml file was stored in $M2_HOME/conf/settings.xml so i linked to that file, cleaned the workspace, tried it again and Viola !Toy
this happened to me also as pointed out by the last answer here, if the path of the workspace same as the project even if the names of the workspace and project are same it wont work .try a different name it willDraconic
F
105

Yes, You should start your Eclipse Workspace out of the pom.xml folder.

for example: D:\workspace\Project_Name.

In your Project_Name folder which contains pom.xml.

So you have to select D:\workspace while starting the eclipse.

And now, then import the project called Project_Name as maven project, It will work.

Hope, it will help !!

Fanaticism answered 18/8, 2016 at 4:46 Comment(3)
As an addition, a good practice is to have the Eclipse workspace folder totally separated from projects to avoid this kind of confusion. The workspace folder only stores Eclipse IDE metadata, there isn't much value to mix it with your actual code.Cypripedium
I've run back to it again. How many times... This solution has to be evaluated +10, not only +1.Saxe
@Fanaticism So you have to select D:\workspace while starting the eclipse. How do I do this stepStern
A
3

1. In Eclipse select -> File -> Switch Workspace -> Other... 2. The choose one directory up from the the one containing pom.xml 3. Import as Maven the project directory one directory up form the one you are intrested in. 4. Select project of interest from the list of projects.

Arianaariane answered 2/7, 2020 at 18:54 Comment(0)
I
1

I also came across this same issue. I kept my eclipse workspace name and existing maven project name same and got the error importing pom.xml. Later i opened new workspace with different name which is not matching to the existing maven project and now i could import maven project.

Intend answered 17/2, 2017 at 15:48 Comment(0)
A
1

Solution:

1.Click on Windows tab then Preference(if you are using Eclipse).

2.Search for the Workspaces first and remove all of them from list(which you can add later eventually)

3.Then search for Maven and choose User Setting and check your .m2 path along with the updated setting.xml(meanwhile check the proxy too)

4.After that restart your eclipse and import the existing maven project again.

I'm 100% percent sure u'll no longer face this issue after that. Good Luck :)

Accipiter answered 4/12, 2017 at 6:47 Comment(0)
C
1

I had the same issue while importing the existing spring project to eclipse, what I did is create a new folder as my workspace, under that I put my spring project, Then reopen eclipse and gave the workspace location as my newly created folder path After that, File -> Import -> Maven -> Existing Maven Projects -> Browser -> (Select the spring project) ->Finish



Chammy answered 9/5, 2021 at 12:37 Comment(0)
G
1

The problem is the project and the workspace must be two different folder. In my case I have erroneously selected my project folder as my workspace folder and so I was unable import the project.

Guillermoguilloche answered 25/1, 2022 at 15:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.