35

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

zalis
  • 1,191
  • 1
  • 11
  • 20
  • please check, if your M2_repo is pointing to the correct path – Saurabh Jhunjhunwala May 02 '15 at 08:37
  • Thanks, its point outside of my workspace to my home directory (mac) Where should it be pointing to normally? – zalis May 02 '15 at 08:41
  • I found the .M2/repository in my home directory so i assume its pointing to the right location – zalis May 02 '15 at 09:00
  • Not sure on Mac, ideally is should point to the location specified in settings.xml – Saurabh Jhunjhunwala May 02 '15 at 09:19
  • 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 settings – zalis May 02 '15 at 09:22
  • in Windows it exists in c:\users\\.m2, not sure on mac – Saurabh Jhunjhunwala May 02 '15 at 09:26
  • 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? – zalis May 02 '15 at 09:32
  • 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. – Saurabh Jhunjhunwala May 02 '15 at 09:33
  • 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 ! – zalis May 02 '15 at 13:10
  • 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 will – Jithesh Chandra Sep 14 '20 at 11:06

6 Answers6

103

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 !!

Ishita Sinha
  • 2,168
  • 4
  • 25
  • 38
chirag28feb
  • 1,056
  • 1
  • 9
  • 6
  • 5
    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. – Mickael Aug 18 '16 at 10:11
  • I've run back to it again. How many times... This solution has to be evaluated +10, not only +1. – hariprasad Aug 31 '18 at 13:35
  • @chirag28feb **So you have to select D:\workspace while starting the eclipse.** How do I do this step – ZAJ Aug 28 '21 at 06:00
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.

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.

gubs
  • 439
  • 3
  • 11
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 :)

0

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



Oshadi
  • 1
  • 1
0

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.

Christian
  • 1,664
  • 1
  • 23
  • 43