Problem with Eclipse and a Maven multi-module project - eclipse

I have created a Maven project with the following structure:
+ root-project
pom.xml (pom)
+ sub-projectA (jar)
+ sub-projectB (jar)
I have done the following steps:
mvn archetype:create –DgroupId=my.group.id –DartifactId=root-project
mvn archetype:create –DgroupId=my.group.id –DartifactId=sub-projectA
mvn archetype:create –DgroupId=my.group.id –DartifactId=sub-projectB
So I have, obviously, in the top-level pom.xml the following elements:
<modules>
<module>sub-projectA</module>
<module>sub-projectB</module>
</modules>
The last step was:
mvn eclipse:clean eclipse:eclipse
Now if I import the root-project in Eclipse, it seems to look at my projects as resources and not like java projects.
However if I import each of child projects sub-projectA and sub-projectB, it looks them like java projects.
This is a big problem for me because I have a deeper hierarchy. Any help would be appreciated!

The maven eclipse plugin does NOT support nested projects so you can't import the root-project and the nested modules (unless you move to a flat layout).
The alternative is to use m2eclipse (and you won't have any problems with a maven-typical nested tree). This is the preferred approach nowadays.

Please follow these simple step's to configure project
Download project from maven project
Inside ch-multi-spring->simple-parent
convert simple-parent to eclipse project using this command
mvn eclipse:eclipse
Import sample-parent in eclipse.
For runing this project
right click on simple-webapp->properties->deployment assemblly->project->
Then add all the dependent project.
Now you can run this project.

I had a similar issue, and the following is what I did to solve it...
I had the parent project open as well as the child projects. The child projects would build fine and not show any problems, however the parent showed the child projects as "resource folders" and they showed as having problems.
Solution was to right click on each of the child projects in the parent project -> Properties -> Resource -> Check "derived"
After you do this, clean/rebuild and you should be good.

Related

Checking out hierarchical Maven project in Eclipse

I have checked out using subversion/subclipse a hierarchical maven project into my Eclipse project.
At first it is a plain folder structure, then I right click->Configure..->Convert to Maven Project.
Now the top node is a Maven project, however all the sub nodes are not recognised as maven projects. I have tried Maven->install and nothing happens.
You have to import the projects as maven projects.
just right-click the package explorer and Import... > Maven projects
to import an existing maven project into Eclipse.
I realise the mistake was that I checked out one level too high. Instead of checking out the root node, I checked out the folder above it.
So in that case Eclipse created a POM file for me for that directory, which confused me into thinking that was the parent POM.
Notice how there is a question mark on the top level POM? It is not in SVN yet.

Maven Multiple module project in Eclipse issue

I have multiple module maven project which i imported in eclipse.
mvn eclipse:eclipse
and it shows child modules as following.
problem is it is not recognizing any of the child modules java files. if hover objects it does not show up any thing and consider as plain text files. it complains that it is not in build path ???
any idea how to fix or how to import multip modules maven project in eclipse.
Maven support is included in Eclipse Kepler. You can find it in the File -> Import screen as Maven -> Existing Maven Projects.
Selecting a directory with a parent POM in it will prompt you to import all its children as well.
If you really want to go down thatroad check out this old school method with eclipse:eclipse and multi-module import plugin.
But I have a different suggestion. Remove all eclipse:eclipse generated files, download m2e (new versions of Eclipse already include it). Then just use m2e Import Maven Project feature. It will recognize nested pom.xml files and let you create separate projects out of the ones you choose to work with.
Source: m2eclipse-book

Maven eclipse - mutli project dependencies not appearing

I have a bunch of maven projects which all are part of a parent project. When I import the parent project into eclipse, I was expecting the child projects source folders to be listed in my parent project, however they are not. They also don't appear in the "Maven Dependencies" section.
Is this the correct behavior or am I missing something. If it is the correct behavior, then what is the best practice around doing this?
Should I be importing each project into eclipse and then editing the build path for my parent project to include them all? I really don't like this approach because I want to do everything through maven.
Note: I am not using mvn eclipse:eclipse to generate my project files, I am using the maven plugin directly in eclipse IDE as: Import existing maven projects
Thanks!
Import your parent project then close it (right click on the project in the package explorer > close project). Select it and go to file > import > maven > existing maven projets here you should see the list of the child projects, select the wanted ones then finish.
Now in your package explorer you should have :
A project parent-project where you work on the pom-parent and eventually on the src-parent
One project per child-project where you work on the corresponding pom-child and src-child
If some dependencies are missing try to update the projects (right click on the projects in the package explorer maven > update project)
Normally you don't have to edit the build path in eclipse it must be handle by the maven nature of the project (the maven nature is often represent by a M on the icons of the projects)
Normally, if you don't import "dependencies" projects, Eclipse simply uses the jars presents in your local repo (.m2).
However, I don't get what you mean by "I have a bunch of maven projects which all are part of a parent project".
Projects are not part of each other. And the child projects sources should not be listed in the sources folders. You only uses the bytecode.
If you want to "see all your sources" :
However, you can have a complete "view" of the code if you export your sources as sources jars.
If you want to be able to debug across your projects :
You then have to import all your projects in Eclipse. If a project is closed, Eclipse will use the jar like if the project was not there. If the project is open, it will use the project (not sure exactly how, but it works smoothly).

Maven integration into eclipse, Problems with Dependencies vs. Referenced Libraries

he fellas, i need your help again.
Im trying to develop a new part for an existing software. The parts are all done using Maven. I have to work in several projects at once, which are all continously opened in Eclipse. In Eclipse i use M2E, but i tend to edit the poms directly in xml.
So, now I can build (clean install) the projects individually, works ok. But Eclipse now has problems with the online help: It shows me errors. Eclipse cant seem to see classes which are placed in the same project, but different packages. Note that it works fine when i compile it!
Also after I run the pom the dependencies dont show up as "Maven Dependencies" but as "Referenced Libraries".
This persists after I run mvn eclipse:eclipse from outside and refresh.
Thanks so much for your help!
"Do not ever do mvn eclipse:eclipse", only do mvn eclipse:clean from command line first and then import "as maven projects" using your eclipse M2E plugin.
M2E Plugin knows how to handle Maven Dependencies, whereas mvn eclipse:eclipse knows how to handle Referenced Libraries, and they are NOT compatible with each other. You can always do mvn update project in Eclipse after mvn eclipse:clean.
I had to delete the maven-project, too, after using eclipse:eclipse. It added the references as "Referenced Libraries".
Manually deleting the .project and .settings files in the project folder and importing the project again helped. I used the M2E import. Afterwards it displayed the libraries within the "Maven Dependencies". Subsequently I was able to run it on my local webserver.
I do not really know the reason for the behavior, but deleting the project and reimporting it solved it.
I agree with kisna. As an alternative to fix the project if already contains both "Referenced Libraries" and "Maven Dependencies", you can do the following:
https://docs.oracle.com/cd/E14545_01/help/oracle.eclipse.tools.weblogic.doc/html/j2eelib/operations/opRemoveLibRefFromClasspath.html
Right-click on the project and select Properties -> Java Build Path -> Libraries tab -> Find the entry in the list of libraries called Shared Library [] or/and all libraries that starts with 'M2_REPO/', and then select it/them and remove.

Eclipse build path with other projects

I've got several projects in Eclipse (all are Maven projects) and one main project (also Maven project) which depends on the rest. I tried add this dependency by setting java build path (right click on project -> preferences -> java build path -> (tab) projects -> add). But there is a problem while executing maven install goal - this is compilation error: ... (class) ... "cannot be resolved" ... - this is definitely looks like maven does't see my resources from other projects. Eclipse is only warning me something like this: "Classpath entry /my-subproject1 will not be exported or published. Runtime ClassNotFoundExceptions may result." These warnings referenced to each subproject and occurs in main project. There is no error messages from Eclipse. In my main project, where I'm importing classes from subprojects, I can right-click on one of the import and choose "Open declaration" and there is valid reference to class from one of my subproject - so it looks like Eclipse sees my dependencies (there is no eclipse errors while building workspace - only these warnings mentioned above) from other projects, but maven doesn't see them while compilation.
Have you got any ideas how can I fix this?
Thanks for help.
You have to declare your dependencies in the pom.xml for Maven. Maven doesn't recognize any Eclipse specific configurations (like Build Path etc.): Maven Tutorial
If you use the m2eclipse plugin, it will configure your Eclipse build path according to your pom.xml configuration
Isn't this maven problem?
Maven needs jar file made from other project inside maven repository.
I don't know much about maven eclipse plugin but so far, in my observation, it seems like it works this way.
So that this case need to build other project so that create it's jar file.
But this takes so much time.