Wednesday, July 15, 2009

Eclipse/maven: solution to cannot nest folders problem

I had the following problem with Eclipse 3.5 (Galileo) and m2Eclipse 0.9.8, but from searching I believe that it occurs with other combinations as well. Situation: I have a maven-ized project in subversion, and I want to check it out into my Eclipse workspace. Method: bring up the subversion repositories view, navigate to the repository folder with the project in it, right click, select the "Check out as Maven Project ..." context-menu option. All seems to be OK – the project gets created, maven dependencies are resolved, etc, except Problem symptom: Eclipse complains that Cannot nest 'rdfutil/src/test/java' inside 'rdfutil/src'. To enable the nesting exclude 'test/' from 'rdfutil/src' (your project name will obviously differ). And there's a red 'compilation failed' triangle in the problems list. Check the Java build path, all is fine. Check the pom.xml, all is fine. What to do? Solution Right-click the project node in the project explorer window to first close it, and then again to delete the project, but without removing the project contents on disk. Then, right-click in the project explorer window to "Import ... > Existing project into workspace ...". Navigate to the location of the project, import, and it comes back without the nested file warning.

16 comments:

gatoatigrado said...

yow did you exclude it in the first place?

Ian said...

Hi gatoaigrado,
Sorry, I'm not sure I understand your question. Can you say a bit more please?

Thanks,
Ian

gatoatigrado said...

Hi Ian,

Thanks for getting back. How did you set up your project to exclude e.g. "src/test" when building "src"? It's not a big issue, mvn from the command line seems to work okay (though I have another unrelated problem).

regards,
Nicholas

Ian said...

Hi Nicholas,
OK, I understand now. In the 'project explorer' view of your project, right-click on the root project node, and from the pop-up menu select 'Build path' > 'Configure build path' (it may be slightly different wording, depending on your eclipse version). That brings up a dialog box with four tabs for configuring the build path: source, projects, libraries, and order & export. Select the source tab, and that will show you which folders are selected as source folders. From there, you can remove or add folders as necessary. In non-maven projects, you can configure the libraries used in your project from the 'libraries' tab, but with m2eclipse the libraries will be populated automatically from the dependencies in the pom.xml.

Hope that helps,
Ian

Marco said...

Hello Ian,

when I try right-click in the project explorer window to "Import ... > Existing project into workspace ..."
he don't recognizes the project. Then, I can't import it.
Do you have any sugestion ?

Thank you.

Ian said...

Hi Marco,
The directory you're trying to import as an existing project should have a .project file in it. If you go there in a command or shell window, and do ls -al (on Linux or Cygwin) or dir /l /o on Windows you should see the .project file listed. If it's there (and readable by the logged-in user), Eclipse should be able to import the project. If it's still not working, you may have to ask on one of the Eclipse discussion forums.

hth,
Ian

Ian said...

Hi Marco,
The directory you're trying to import as an existing project should have a .project file in it. If you go there in a command or shell window, and do ls -al (on Linux or Cygwin) or dir /l /o on Windows you should see the .project file listed. If it's there (and readable by the logged-in user), Eclipse should be able to import the project. If it's still not working, you may have to ask on one of the Eclipse discussion forums.

hth,
Ian

Marco said...

Ian !

The project was created with modules and with Maven.
When I import as Maven Project he shows all modules like projects.
But when I import as you said, he makes just one central project (with the .project) with the modules as folders.

I don't know which one is the correct way of importing, when I import the project as Maven Project and compile, the other project with depedencies
work fine, otherwise, when importing like eclipse project, the other projects with dependencies to this projects do not compile.

Is this correct?

Thank you for helping me, and sorry for my bad english.

Marco said...

Sorry, I was wrong.
The projects aren't even imported with the import 'Existing Projects into Workspace'.
I will try to fix it.
Should the .project be created with Maven projects ?

att,
Marco.

Ian said...

Hi Marco,
I'm not sure that continuing this discussion via blog comments is very efficient. Please feel free to email me: i dot j dot dickinson at gmail dot com.

As for your question, if you are initially creating the project in Eclipse using the maven plugin, then Eclipse will create the .project for you. If you are creating the maven project from the command line, you should use the Eclipse archetype. See http://maven.apache.org/guides/mini/guide-ide-eclipse.html.

Thomas said...

Another way to deal with this (have to admit deleting the project made me a bit nervous, although I do realize that I'd be leaving the actual files still in place), I just navigated to the Problems tab, right-clicked on the reported error, and chose "Delete", which removed the reported error.

The error will return if you right-click the project, select Maven -> Update Project Configuration. Seems that this is an issue with M2Eclipse (using v0.9.8.200905041414)

Julián said...

Tahnks for your help.smo

miguelbaldi said...

It doesnt work for me. Close project, delete, and import.

Anonymous said...

I find other way because this dont work...
First go build path and add new source folder and link it to you problematic folder, click in ok, refresh project, and back to build path.. now exclude the source folder that you created and in inside your main sorce folder yet in build path, dele all pattenrs in excluded option..

Sry for my english..

Régis N. Machado
Brasil,Pelotas-RS
Faculdade de tecnologia Senac-rs
Universidade Federal de Pelotas

Anonymous said...

This didnt resolve mine unfortunately. Arun

Devender Singh said...

Guys - not sure if anyone is still running into this issue. I am posting what worked for me.

1. Go to Project's Build Path > Sources - remove all folders.

2. Invoke Maven > Update Project

3. You should see Maven Dependencies in your Libraries Tab.

4. Add your source folders again.

Hope this helps.