Importing multiple multi module projects as maven project at once in eclipse - eclipse

My workspace contains more than 100 maven projects and at a time I only need to import around 70 projects in workspace.
Please check this image I attached m2e shows the project hierarchy based on dependency. What I have to do now is select every project pom, which I want to import.
So is there any way by which we can specify a list of project that can be imported as maven project rather than selecting required project manually.

Have you tried File -> Import -> Maven -> Existing Maven Projects? You specify directory where all your projects are and eclipse will automatically detects all maven projects underneath it. You can then select All or select them individually. In your case you can select All and then deselect 30 which you don't need.
PS - this assume you have m2eclipse plugin install. If not you can install it or eclipse might just prompt you to install one when you try above steps.

Related

Multi-module Maven with Profile in Eclipse Doesn't Resolve Dependencies on Children

For my setup, I have profiles defined in my ~/.m2/settings.xml, where the profiles define some project-specific repositories. From the command line, I can successfully build the projects using -PprofileHere. However, the profile isn't enabled automatically (i.e. activeByDefault is not set to true for the profile).
In Eclipse 4.5.1 (Mars 1) with m2e 1.6.2.20150902-0002, I import the projects using Import → Maven → Existing Maven Projects. I select the parent project and Eclipse imports them. The children projects are imported, but as expected, their dependencies aren't correctly resolved. To attempt to fix this, I select the parent project, right-click Maven → Select Maven Profiles... and select the correct profile for the parent. I then do the m2e tango by trying various combinations of the following:
Cleaning and rebuilding the project (Project → Clean...)
Updating the parent project (Right-click, Maven → Update Project...)
Updating the children projects (ditto)
Restarting Eclipse
Eclipse continuously shows the dependencies unresolved on the children projects when viewing the children pom.xml's or opening a class in a child module with unresolved dependencies. The only workaround I've found is by enabling the profile automatically in my ~/.m2/settings.xml. Then and only then does Eclipse properly resolve the Maven dependencies.
What am I doing wrong when originally importing / configuring projects in Eclipse?
How it worked for me in a sample project providing the same scenario: make Eclipse use a profile by default for a Maven build.
Right click on the concerned project > Properties > Maven
Type your profile there, it will be used by Eclipse during the build
I never used this option, but apparently its purpose should suit your need.

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

Importing projects into Eclipse

I have this simple question how to import whole project source into Ecplise so I can browse it easily? Specifically, I have downloaded Maven source code http://maven.apache.org/download.html and I just want to view it same as other projects in my Eclipse.
I've tried to import it with use of two possible options (as archive and as a project) without luck.
Thank you in advance!
Maven itself is a Mavenized multi-module project, Generally there are two ways to import a Mavenized project into a IDE like eclipse:
Pre-requirment:
Suppose you have installed Maven 3 and setup environment variable
properly.
if you use Eclipse, you also need add M2_REPO to you
Build Path -- Classpath Variable, check out here for how to
setup. this tells Eclipse where to find jar dependencies stored in
local maven repository.
Option 1 -- Import as Java Project:
Open a command prompt and go to the extracted source folder, run mvn eclipse:eclipse
and waiting for it finish, make sure it doesn't popup any message start with [ERROR], this
will download all required jar dependencies from internet to you
local maven repository and create .project and .classpath for Eclipse
to use when doing import.
In eclipse, go to File -- Import -- General -- Existing Project into
Workspace, select the extracted source folder as root directory. This
will import a group of projects into Eclipse as bunch of regular java
projects (i.e. project icon inside Package Explorer watermarked with a
capital J).
Option 2 -- Import as Maven Project:
Alternatively, if yo got m2e plugin installed in Eclipse, you can
directly import the extracted project folder, go to File -- Import --
Maven -- Existing Maven Projects, select the extracted source folder
as Root Directory. This will import a group of projects into Eclipse
as bunch of Maven projects (project icon inside Package Explorer
watermarked with a Capital M).
Hope this helps.
The maven repository versions are not uploaded in the exact format they are on disc (from where the the mvn deploy goal is run. I can think of 3 options assuming I understand your question correctly:
You can find the open source project if it exists and get all the
source and project from there.
On an existing project, you go the dependencies, right click on one
and select browse source. Not the same as having the show project
here you can build and run however.
You can download the sources from the maven repo and then
reconstruct the project. I'm not not sure how feasible this
actually is and I have never tried it. I would probably find other
ways before trying this.

m2eclipse not finding maven dependencies, artifacts not found

I'm using m2eclipse as my maven 2 plugin for eclipse. I'm brand new to maven, so my mistake might be simple, although searching has not yielded any solutions for me. I can run maven from the command line and it build successfully. However if I import as an existing maven project, or use mvn eclipse:eclipse and then import I get the artifacts not found in my POM file resulting in no maven dependencies being loaded at all.
What's odd is that I have 2 projects, both children to a parent pom packaged project. One child loads all my maven dependencies while the other cannot find any and says my pom file is missing artifacts. Again, I can install and package them all just fine from the command line.
I even tried loading my projects into netbeans which worked flawlessly, however I am required to use eclipse.
Any ideas on how to fix this?
Update
Directory structure, pom files layout:
--main
--pom.xml (is a pom package that is the parent to two other projects)
--ProjectA
--pom.xml
--ProjectB
--pom.xml
Main is the parent project of both ProjectA and ProjectB. ProjectB has ProjectA as a dependency. Apprently m2eclipse is not happy about that depedency. As soon as I remove the dependency of ProjectA from ProjectB's pom file all the maven dependencies are found by eclipse.
- com.company.myproj:app:6.6.0:jar Missing: ---------- 1) com.company.myproj:main:pom:${myproj.version} ---------- 1 required artifact is missing. for artifact: com.company.myproj:main:pom:$
{myproj.version} from the specified remote repositories: apache-incubating (http://people.apache.org/repo/m2-incubating-repository/, releases=true, snapshots=true), central (http://
repo1.maven.org/maven2, releases=true, snapshots=false)
However, I still need ProjectB to have that dependency for ProjectA. The error message seems to be m2eclipse looking for ProjectA in a remote repo. Project A should only be in .m2 directory, but I'm not sure how to tell m2eclipse to look there.
I think this may be just a m2eclipse specific issue because using mvn from the command line works fine and like I said previously, netbeans loads the projects and dependencies just fine.
I had this issue for dependencies that were created in other projects. Downloaded thirdparty dependencies showed up fine in the build path, but not a library that I had created.
SOLUTION: In the project that is not building correctly, right-click on the project and choose Properties, and then Maven. Uncheck the box labeled "Resolve dependencies from Workspace projects", hit Apply, and then OK. Right-click again on your project and do a Maven->Update Snapshots (or Update Dependencies) and your errors should go away when your project rebuilds (automatically if you have auto-build enabled).
It sounds like your m2eclipse install is using the embedded Maven, which has its own repository (located under user home) and settings.
If you open up the Maven preferences (Window->Preferences->Maven->Installations, you can add your Maven installation by selecting Add... then browsing to the M2_HOME directory.
(source: sonatype.com)
For more details see the m2eclipse book
For me maven was downloading the dependency but was unable to add it to the classpath. I saw my .classpath of the project,it didnt have any maven-related entry. When I added
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>
the issue got resolved for me.
One of the reason I found was why it doesn't find a jar from repository might be because the .pom file for that particular jar might be missing or corrupt. Just correct it and try to load from local repository.
Okay I fixed this thing. Had to first convert the projects to Maven Projects, then remove them from the Eclipse workspace, and then re-import them.
I had problems with using m2eclipse (i.e. it did not appear to be installed at all) but I develop a project using IAM - maven plugin for eclipse supported by Eclipse Foundation (or hosted or something like that).
I had sometimes problems as sometimes some strange error appeared for project (it couldn't move something) but simple command (run from eclipse as task or from console) + refresh (F5) solved all problems:
mvn clean
However please note that I created project in eclipse. However I modified pom.xml by hand.
This could be a problem if you are using a custom 'Settings.xml', with a different <localRepository> configured in it.
Eclipse will be using the default installation of MAVEN, and will be using the default location for the User to look for the local Maven repository, which on Linux systems would be '/home/${USER}/.m2/'
Eclipse can be easily configured to use the customized 'Settings.xml', by doing the following:
Goto -> Window -> Preferences -> Select 'Maven' -> Select 'User Settings'
Under 'User Settings', select the custom 'Settings.xml' file, for 'User Settings' by clicking 'Browse' and selecting the customized 'Settings.xml'.
Click on 'Update Settings', if the 'Local Repository' Textbox does not show the custom location from the file above, just key in the location and click 'Reindex'.
Click 'OK'
After this, you could proceed to select your project from the 'Project Explorer', right click, Select 'Maven' > 'Update Project'. Make sure that your project is selected (ticked) in the Window, and click 'OK'.
This should help to resolve the issue, if using custom 'Settings.xml' for Maven.
Hope it helps.