Maven beginner question, get m2eclipse to download jar and add to build path? - maven

From what I have read, after adding the relevant maven repositories, maven should automatically download the necessary jars to satisfy dependencies in the pom.xml file.
However, no jars ever get downloaded for me after I add dependencies in eclipse. Am I missing some glaringly obvious step?

I'd recommend to start from creating your project with m2eclipse. See more details in this article.
Basically, you need to make sure the following:
your Eclipse project has a valid pom.xml and all dependencies are available (you should see errors on Maven console, in the Problems or Markers view or when opening pom.xml in m2eclipse's POM editor)
Maven support is enabled for this project (you can use Maven / Enable Dependency Management from popup menu on that project)
project configuration is in sync with pom.xml (you can use Maven / Update Project Configuration from the project popup menu)
you can also use Maven / Update Dependencies to refresh your dependencies (e.g. when you got them in your Local Maven repo from the command line)

Dependencies jars aren't in your project but in your local maven repository.
These jars will be automatically used when you compile you project with maven (or m2eclipse).
If you don't have the needed jar yet, maven will download it for you.

Related

How to add unmanned jars directory to specif profile in Maven with out install

I want to add my jars library which is c:\tmp\jars\ (more than 100 jars files) to specific profile in Maven with out installing.
Installing each jar in maven and adding each dependency is not i'm looking.
I'm using Intellij and Maven
I can add the jar directory by project module settings add Jars but its applicable to all profiles, i want add this jars to specific profile.
for example y project has 2 profiles hdp,azure
for hdp profile the external jars not required but azure profile the external jar required.
Agian I don't want to install in maven add each dependency is not my option.
If the jars are not listed as dependencies in your POM, Maven cannot see them.
Even if IntelliJ sees them, you get a strange hybrid project that Maven cannot build any more.

Update Maven Dependencies Jars

I am new to Maven and have a quick question. I am using the JBoss IDE and have my Maven project set up. I have several jar files in my Maven Dependencies build path that need to be updated to a newer version. I have tried adding the external jars manually, but they do not go within the Maven Dependencies library and the outdated jar remains within that library.
What is the best way to update the jars with the Maven Dependencies library?

Maven takes dependency from workspace and not from local repository

I have a web maven project in eclipse, one of its dependencies is a j2se maven project that I have in the same workspace. Something curious to me is that I believed that all dependencies declared in a maven project were taken from the remote repository or a local repository but its not, I mean; even I havent done a maven install to my j2se java project(so its not located in the local repository), when I create a war from the web project this jar is included.
I think this behaviour is because of eclipse and not maven and eclipse will always takes this dependency from the workspace
2 Because of this I can change the j2se project and not have to do a maven install ever to this project,
From the point of view of maven, I should do a maven install to my j2se project in order the web project takes the dependency from the repository and not from workspace, right?
Thanks
Yes, Eclipse m2e will by default try to resolve dependencies from the workspace. In case it's not present in the workspace, it will try to resolve it from the ArtifactRepositories(your local and remote repos).
In case you want to turn off the workspace resolution, you can do that by right clicking on the Project and selecting Maven.If you uncheck that check-box, the dependencies for that particular project won't be resolved from the workspace.

gral-examples Maven dependency

I added gral-core Maven dependency to my project as it is explained here
http://trac.erichseifert.de/gral/wiki/Download
Problem is that I also need to add gral-examples.jar in Maven dependencies, but I cannot find the code for it. I need this to work because I share this project with few other people via EGit plugin for Eclipse, so I can't just add this library to build path, I need it to be Maven dependency.

m2eclipse says "Missing artifact" but I can build from cmdline!

I'm trying to use this Sonatype Eclipse plugin for the first time to handle an existing (huge) software that I can build with maven form the command line.
I have configured the plugin to use my maven 2.2.1 installation instead of the built-in Maven 3.
In Eclipse I have 25 projects (loaded through the root pom.xml) and 4 of them have compilation errors; the maven console contains a lot of lines like this one:
Missing artifact commons-logging:commons-logging:jar:1.0.4:compile
I have all the jars in my repository and the M2_REPO classpath variable correctly defined. Why the plugin doesn't see all the jars?
The .classpath file of those projects simply references "MAVEN2_CLASSPATH_CONTAINER", there isn't a list of the jars.
The pom.xml in Eclipse shows an error on the first line for the missing jars but I can build from the command line!
Any idea? I need help! I will try to move to NetBeans if I don't solve this problem.
Thank you.
You may need to to tell Eclipse to force update:
Project -> Maven -> Update Maven Project
and then make sure you have selected:
Force Updates of Snapshots/Releases
this happens when mvn install copies some jar files into Maven repository and Eclipse had checked this repo BEFORE this jar has been copied there.
If Dependency management is enabled when the above problems occur in Eclipse you can Project > Maven > Disable Dependency Management and then \Project > Maven > Enable Dependency Management. This normally remove any dependency errors in the pom.xml.
Also do as #Nishant indicated in his answer above after the above steps to complete the projects dependencies.
right click on your project > Maven > Update Dependencies
then
right click on your project > Maven > Update Project configuration
Assuming you M2Eclipse plugin is installed correctly this should solve the issue. Also, check if there is an option right click project > Maven > Enable dependency Management select that.
Using Eclipse Kepler, the removing and re-adding of the maven nature fixed this same issue I was having. What this process actually did was modify the .settings/org.eclipse.m2e.core.prefs file, changing the line
resolveWorkspaceProjects=false
to
resolveWorkspaceProjects=true
So you could probably make this change manually if you had to.
Adding my 2c for future Googlers:
Whenever this problem shows up, I delete the corresponding folder from the m2 repository (on a mac it's on ~/.m2/repository) and build again from eclipse with clean install.
Works every single time.
Close eclipse IDE and open it again, this issue should be fixed.
Just to add yet another possible resolution, if you have a multi-project build with interdependencies, if you have a repository defined in a child project pom to resolve a specific dependency that only that project depends on and it is relying on a partent project for it's other resolutions it fails to see those dependencies in the child project (even though it works from the command line).
Move the repo definition to the parent pom.
The lack of jars in the build path suggests you haven't enabled Maven dependencies. Right-click on the project, select Maven, select "Enable Maven Dependency Management". This allows M2Eclipse to reference your POM.
I finally found a workaround. It is surely a bug in m2eclipse, however the problem disappeared when I added quartz-1.6.0.pom next to quartz-1.6.0.jar in .m2\repository\opensymphony\quartz\1.6.0\
The pom is not present at http://repo1.maven.org/maven2/opensymphony/quartz/1.6.0/ but you can extract it from quartz-1.6.0-bundle.jar linket at http://jira.opensymphony.com/browse/QUARTZ-482
It's a strange solution but it worked on the PCs of my collegues too.
None of the other suggestions worked, but the following steps worked for me (SpringSource Tool Suite 2.6.1):
Back up the contents of the local Maven repository
Delete the repository
Project > Maven > Update Dependencies
Replace anything not available in a public repository from the backup
If disabling and enabling project dependency management doesn't help (usualy it helps) you can modify .classpath file in your project and add a line:
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>
After eclipse restart dependencies should be added.
I had this same problem happened to me. On the CLI clean install, then on eclipse delete the dependency, paste it again and that did the trick.
Remove all the artifacts except the jar in maven local repository
Late answer: In my case I had multiple profiles in settings.xml. Building worked since the correct profile was selected in the Maven Build run config, but the editors showed errors because the profile was not selected via Project -> Maven -> Select Maven Profiles ...

Resources