Eclipse m2eclipse getting dependencies from local repository - eclipse

I have dependencies installed local on my machine (~/.m2/repository/blah/blah/blah) and m2eclipse is not recognizing them as there - I think m2eclipse is using its own maven instance. Is there any way to force m2eclipse to use the local maven installation in osx?

I had the same problem, and this is what worked for me. Using Eclipse Indigo:
Windows->Show View->Other
In the pop-up:
Maven->Maven Repositories
Once the view is displayed, right click on the appropriate repo, and select "Rebuild Index"
Wait a few seconds and done!

I have dependencies installed local on my machine (~/.m2/repository/blah/blah/blah) and m2eclipse is not recognizing them as there.
Do they have good metadata? How did you install them? Because m2eclipse definitely uses your local repository for dependency resolution.
I think m2eclipse is using its own maven instance. Is there any way to force m2eclipse to use the local maven installation in osx?
Yes, m2eclipse uses its own version of Maven by default and you can add an external installation via Window > Preferences > Maven > Installations but this won't change anything to the local repository used by one or the other that you can configure via Window > Preferences > Maven > User Settings as shown below:
alt text http://www.imagebanana.com/img/w5y2vevt/screenshot_008.png
This send us back to the questions above: how did you "install" the problematic dependencies?

You can change the used Maven instance in Windows->Preferences->Maven->Installations. But I'm not sure whether this will help as a comment below that setting says that dependency resolution will still be done with the internal Maven installation.
If I were you, I would try to add that local repository to the list of known repositories. Use Window->Show View->Maven repositories (this is sadly not visible in the preferences).

Check that the jar was installed properly. Maven does not give an error when you provide an incorrect path to the jar when installing to local repository. The jgravatar.jar was not in my ~ directory when I ran the command below.
mvn install:install-file -Dfile=~/jgravatar.jar -DgroupId=jgravatar -DartifactId=jgravatar -Dversion=06292012 -Dpackaging=jar
[INFO] Installing /Users/steve/~/jgravatar.jar to /Users/steve/.m2/repository/jgravatar/jgravatar/06292012/jgravatar-06292012.jar
[INFO] Installing /var/folders/gz/gjyqtkzj3ys8lpmh_38qvmn00000gq/T/mvninstall2662938607942511865.pom to /Users/steve/.m2/repository/jgravatar/jgravatar/06292012/jgravatar-06292012.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------

I was getting the exact same issue. I added the JARs to the local repository via the install-file command. I verified they were installed. I rebuilt the index. I went to the directory and inspected the JAR file using 7Zip, but I could not get it to appear in the Maven Dependencies inside of my eclipse project.
For me the solution was pretty silly. When I added the dependency into the pom.xml using the dependencies editor, Maven threw in a packaging stanza into the XML. So the XML entry looked like:
<dependency>
<groupId>slf4j</groupId>
<artifactId>jdk14</artifactId>
<version>1.5.8</version>
<type>JAR</type>
</dependency>
When I removed the last stanza "JAR" and made the entry:
<dependency>
<groupId>slf4j</groupId>
<artifactId>jdk14</artifactId>
<version>1.5.8</version>
</dependency>
it all worked fine.

Related

Using a local dependency in Eclipse with Ivy / Ant

I have an ivy.xml file with remote dependencies to a library I own, for example
<dependency org="myorg" name="myProjectLib" rev="default" conf="default"/>
In Eclipse , if I have the myProjectLib project in my workspace, and want to depend on that version, instead of the remote one I have to
1) go to the project Properties -> Java Build Path -> Projects ->Required Projects on BuildPath and add the local project dependency there and
2) comment out the remote project dependency in my ivy.xml file, in order to actually be using the local dependency when running the project locally .
<!-- <dependency org="myorg" name="myProjectLib" rev="default" conf="default"/> -->
This seems like a step too many for me . I don't have this issue in IntelliJ for example. In that, I can just set it to depend on the local project and do not have to change the ivy file. I often run into dependency issues in Eclipse by commenting out the remote dependency. Any ideas/ suggestions on another way to do this or how to simplify this workflow?
When adding a project as a dependency manually, you should also consider the order of the classpath entries. If the IvyDE classpath container is before the dependent project, then the resolved jars by Ivy will take precedence over the projects in Eclipse. If you move manually the project dependency to be upper than the IvyDE classpath container, then you should see the expected behavior.
Then regarding an even more simpler configuration, you can configure the IvyDE classpath container to lookup for dependencies directly in the workspace. Both of your projects should have their dependencies managed by Ivy in Eclipse. And then see "Resolve dependencies in workspace" in the settings of the IvyDE classpath container.
More info about that feature can be found in the doc: https://ant.apache.org/ivy/ivyde/history/latest-milestone/cpc/workspace.html

Eclipse: The project was not built since its build path is incomplete. Cannot find guava Predicate

I am using new Eclipse Oxygen. My project setup includes Maven. One of the Maven dependencies is Guava:
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>20.0</version>
</dependency>
There are 2 problems I am facing that do not allow me to build the project:
1.
The project was not built since its build path is incomplete. Cannot find the class file for com.google.common.base.Predicate. Fix the build path then try building this project
2.
The type com.google.common.base.Predicate cannot be resolved. It is indirectly referenced from required .class files [...] Java Problem
Here is what I tried to solve it:
I have made clean & build of my project; I have closed and then reopened it; I have removed it from Eclipse and then re-imported and made clean & build.
Nothing seems to help.
Anyone has any ideas? This is super annoying.
The problem was not related to Eclipse, but it was a maven issue.
In order to fix it I had to clear ~/.m2/repository folder and run Maven->Update Project in Eclipse.
Eclipse by default uses embedded Maven. It is possible, that the guava dependency got corrupted in the embedded Maven's .m2 folder. Try to delete it from there.
Also try to change the Maven in Eclipse to use the same Maven as you use in the command line in:
Preferences->Maven->Installations

NocloassDefFound Error in Eclipse

I get a java.lang.NoClassDefFoundError: org/apache/http/impl/conn/PoolingHttpClientConnectionManager when trying to build a maven project in eclipse. Where as it builds successfully on command line
I get the above mentioned class through the following dependency defined in the pom
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.3.4</version>
</dependency>
--I tried, deleting the local repo and running the build with -U option but doesnt seem to fix the problem.
--When I look at the java build path in eclipse, it shows certain libraries missing. I found newer versions of these jars in the local repo and added them in the eclipse java build path. But the build still fails for the same error
Note: I have one multimodule project in my eclipse workspace.
--I tried updating the project and verified if eclipse was using teh same settings.xml and local repo that the command line is.
--I am running a clean install
--Cleaning project also doesnt fix it
--I looked at the referrenced libraries and there is a class org/apache/http/impl/conn/PoolingHttpClientConnectionManager present. Dont know why it doesnt find it
If project builds on command line it should build in Eclipse as well. Reasons why it may not be the case include:
settings.xml used by Eclipse is different, so Maven does not have access to same repos. This can be changed in preferences.
Workspace resolution is picking code in dependent projects that have local changes and thus build fails
Eclipse maven configuration is not up-to-date that can be fixed by using Maven->Update project .. option
Try that if it fails please clarify if you have one project in Eclipse or multiple and what errors exactly do you see.
Also note that sometimes maven build from command line will delete target folder and will cause Eclipse to run build in parallel re-using same target folder and resulting in inconsistent state.
Try Adding dependency for HttpCore library, the class exists there too
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.3</version>
So the problem was that I had two versions of http-client library. I excluded one of them from the pom

Where can I obtain the maven-source-plugin?

I checked out an open-source project from SourceForge's SVN source control using the Eclipse Maven plugin. After it checks out, I get this error in the pom.xml file:
Error resolving version for plugin
'org.apache.maven.plugins:maven-source-plugin' from the repositories
[local (C:\Documents and Settings\thomas.owens\.m2\repository),
central (http://repo1.maven.org/maven2)]: Plugin not found in any
plugin repository
I'm fairly new to Maven, but I followed the installation instructions for Apache Maven and the Eclipse plugin. It seems weird that this plugin would not be found in the central plugin repository for Maven or my local repository, when I can clearly see a directory located at C:\Documents and Settings\thomas.owens\.m2\repository\org\apache\maven\plugins\maven-source-plugin that contains a single resolver-status.properties file.
Any thoughts as to why this plugin might not be found and where I can find it?
The problem that I was encountering was not an issue with the maven-source-plugin, but incorrect proxy settings that was preventing the connection to the repositories. The answers to this question on the use of Maven with a proxy helped me to find the mistake and correct it.
That plugin is in the central repository.
Perhaps you just need to run with -U to update:
mvn -U clean install
Or in Eclipse: right-click on the project, select Maven-> Update Dependencies, (perhaps) Maven-> Update Project Configuration
Check if you are able to see Maven in Eclipse, Window > Preferences.
If so, select Maven and go to installations and check if the folder, in where maven was installed, is properly set. Then, set your setting.xml file, it should be in /(maven installation folder)/conf/
Then, right click in your project go to Maven > Update Maven Dependencies.
Did it help?
Which project?
Perhaps there is a bug in their pom.
Or perhaps they require a 'standardized' develop environment with specific environment variables set, or a specific setting in user.home/.m2/settings.xml

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.