Eclipse m2e multi-module project checkout and convert to maven - eclipse

I have recently had need to checkout an apache project to do some fact-finding/debugging (specifically maven-surefire-plugin, see this question). This, like most other apache projects, is a maven multi-module project. So, in eclipse, I open up the SVN Repositories browswer, add a new repository, find the project and right-click->Checkout.... In the wizard, I click Checkout as a project in the workspace and type in the name of the project.
I have the project, now I need to let eclipse know its a maven project, so right-click->Configure->Convert to Maven Project. Now the parent project is a maven project. I can right-click->Run As->Maven Build and it works. But, all the modules are just folders. Eclipse doesn't know anything about where the source code is or even if it has any. In a single module project it would have set the source folder, build folder and other configuration automatically. Further more, if you are creating a multi-module project from scratch, you start by creating the parent project, then, when you add modules to it, they each show up as individual projects in eclipse with the physical directory living under the parent project folder as needed by the default maven build process.
So now, knowing how its done when creating new projects I can File->New->Project..., choose General->Project, give the project a name (I match it to the module name), uncheck Use default location and set Location: to the path on to the module inside of the parent project folder. After clicking Finish, and repeating the process for each other module I have something that looks similar to what I would expect. I now need to convert every individual module to a maven module in the same fashion as the parent project. Great, they are all maven projects, right?
So then I open them up, and the source folder is not set.
Argh... Then I go to each project, twist it open, and on the src folder I right-click->Build Path->Use as Source Folder. Lather, rinse, repeat... Once done on all the projects, it really looks and feels like I started this project from scratch. Things function.
My question is, is it really this hard? Am I missing a shortcut? Wouldn't it make sense if Configure->Convert to Maven Project on the parent pom realized it was a multi-module project and did all the work for me? This is a very painful process for apache projects as they all seem to have many, many, modules... Anyone know of a better process?

You could try to pull all the code down outside of Eclipse, import the parent project as an existing Maven project (right-click -> Import... -> Existing Maven Projects), and see if it all comes in the way you expect. Then right-click -> Team -> Share Project... on the parent project.

Related

Maven modules projects no longer showing as maven project inside the parent project

I have this parent Maven project and inside it I have 6 modules, It was created on Eclipse Neon and there everything is showing correct regarding the project structure.
The problem is after putting the project on a SVN repository and importing in another Eclipse, in this case, all the modules inside the parent project no longer show as maven project but just a normal folder.
What could be wrong? Anything on Eclipse? Any plugin? This Eclipse with the wrong view is the latest one, java-2019-09.
I need ideas :)
Edit 1:
Edit 2:
To import the nested projects use File > Open Projects from File System... and choose as Import source the directory of the (already imported) parent project.
By the way, the parent project should be a General Maven project instead of a Java Maven project.

are there different ways of importing git repository to Eclipse?

Why when I import a git project it does not appear like full package path view (main.java.comformance) like this image:
I have imported this project before but now in the package view, it only appears as a tree of folders and not full package path view like main.java.comformance with package icons. I wonder what I'm doing differently now. I followed the instructions in this video: https://www.youtube.com/watch?v=L8IeaWHZCRo)?
Both projects on the screenshot do not seem to be configured correctly (probably because they were not created with Eclipse or files like .project were not shared):
The project on the right side is obviously a Maven project (with probably this pom.xml file): the Java source folder should be src/main/java/ (default of Maven) instead of src (default of Eclipse) and the Java packages for instance uk.ac.manchester.cs.jfact instead of main.java.uk.ac.manchester.cs.jfact.
The project on the left side is not even configured as a Java project.
The simplest way is to use the Eclipse Smart Import feature (instead of configure everything manually): the Java nature of the project will be detected even without the .project file and also the pom.xml file is read to get the required JARs and to configure the Java build path and source folder(s) automatically:
Clone the Git repository
In the Git Repositories view right-click the Working Tree node and choose Import Projects...
Do you see the "J" in the icon next to the project name "jfact" at the right image?
That means that it is a "java" project. Eclipse does not know anything about your project.
You will have to do one of this:
Checkout the project again with Eclipse and use a "wizard" configuring it as a java project.
Enable Project Facets (right-click on the project name), and then enable "Java" in the Project Properties/Facets. This is not trivial, so I don't recommend this. - If this is a solution, actually I don't know for sure -
If you are using maven, close the project and execute mvn eclipse:eclipse to convert/create the project files for eclipse, and open again the project.
After you manage it to become a Java project, furter steps could be needed, but maybe will be enough.

Maven in eclipse not showing all folders

I am new to Maven and have been trying to get a project working with Eclipse, hibernate,Maven and mysql. I am stuck at the very first step. I have everything configured properly i think and if i create a new Maven project in eclipse it does not show me any folder under src/main or src/test. although if i go back to that folder in the workspace it has a src/main/java
FUrthermore the src/main/resources folder is not created at the time of project creation?
Any clue what the problem maybe or how i can fix it?
Thank you!
For your first problem, when you create a new Maven project the folders that get created depend on the archetype you choose. Assuming you chose quickstart, then it does create (assuming you chose com.example as your package in the wizard and example-project as your artifactId):
And it configures the project so that /src/main/java is in the Build Path. That said, if you are viewing your project in the Package Explorer view, then the packages are shown outside of the folder structure. So, you would see the the com.example.example_project package containing App.java in the build folder /src/main/java and you would see the com.example.example_project package containing AppTest.java in the build folder /src/test/java. These would show up above the libraries which is above non-build folders which is where you see the src folder.
To answer your second question, no, /src/main/resources is not generated assuming you chose the quickstart archetype (this is governed by the quickstart archetype and does the same thing whether generated in eclipse or on the command line).
And third, to fix this (I assume you mean add the resources folder), find the src/java folder (below the libraries), right click and choose New->Folder. Name it resources. Then right click your project, choose Maven->Update Project. This will cause maven eclipse to reconfigure the project according to the Maven configuration which will result in the /src/main/resources being added to the build path. As such, it will get moved above the libraries next to /src/main/java and /src/test/java.

Eclipse adding the project overrides maven dependency

I have a maven project that uses other small projects. And I added them to master's pom file.
So my Eclipse project properties looks like following:
>Master project
>Java Resources
>Libraries
>JRE System Library
>Maven dependencies
>smallProj1.jar
>smallProj2.jar
The thing is I do not have the all code for smallProj1 and smallProj2 and whenever add them to my workspace Eclipse overrides the maven dependencies and simply calls the two projects instead the jar files from my local maven repository and then I have all over the code those red underlines. Project properties in Eclipse looks as following after I add them to my workspace:
>Master project
>smallProj1
>smallProj2
>Java Resources
>Libraries
>JRE System Library
>Maven dependencies
>smallProj1 (not jar anymore - folder)
>smallProj2 (not jar anymore - folder)
Since I also want to have a look to smallProj1 and smallProj2 code while I am coding, I want to keep them both in my workspace. But I want my Master project to use the jar files that I provided, not the small projects in the workspace.
Any ideas on that?
You could right click on a project and set "Maven" -> "Disable Workspace Resolution". This will let Maven find the dependencies from Maven and not within the workspace. I don't think it is possible to do this on a dependency basis.
But I think in your case it would be better to fix the broken smallProjX in your workspace (as they exactly contain the code you need), so that the master project could be build correctly.

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).