Maven not downloading dependencies in Eclipse - java

I am setting up a project in eclipse . This projects builds successfully through command line(all mvn commands like mvn package, mvn compile, mvn clean install) work perfectly fine. While setting up this project on STS or Eclipse . I see some of the dependencies are not getting downloaded even though they are present in pom.xml. However, searching them in the maven repository and downloading the jar to my local computer and then adding them to build path makes it work on Eclipse.
Is there anything that we need to do to eclipse to make sure it downloads all the dependencies from the repository.
My POM:
<dependency>
<groupId>org.apache.bookkeeper</groupId>
<artifactId>bookkeeper-server-compat410</artifactId>
<version>4.1.0</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.apache.bookkeeper</groupId>
<artifactId>bookkeeper-server</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.bookkeeper</groupId>
<artifactId>bookkeeper-server-compat420</artifactId>
<version>4.2.0</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.apache.bookkeeper</groupId>
<artifactId>bookkeeper-server</artifactId>
</exclusion>
</exclusions>
</dependency>
Both these artifacts were not downloaded for eclipse and there jars found http://mvnrepository.com/artifact/org.apache.bookkeeper/bookkeeper-server-compat410/4.1.0 and http://mvnrepository.com/artifact/org.apache.bookkeeper/bookkeeper-server-compat420/4.2.0 were not present in the folder for MavenDependencies and were subsequently giving errors in Eclipse.
However manually adding them to the build path created a new folder (Reference Library) and resolved the Eclipse Errors . Why did Eclipse not download and import these dependencies by themselves from the maven repository ?? Is it a bug in Eclipse or some problem from my side . Please help.

I got the same problem and this is how i solved. :
Right click your project, choose Run As -> Maven install.
Observe the output console to see the installation progress. After
the installation is finished, you can continue to the next step.
Right click your Spring MVC project, choose Maven -> Update Project.
Choose your project and click OK. Wait until update process is
finished.
The error still yet, then do Project->Clean and then be sure you have selected our project directory and then do the follow Project->Build.

Solution 1:
Set correct proxy:
<proxy>
<id>optional</id>
<active>false</active>
<protocol>http</protocol>
<username></username>
<password></password>
<host>172.27.171.91</host>
<port>8080</port>
</proxy>
Solution2 :
just delete
lastupdated extension files from folder
and try updating maven.
[Most of the times this solution will work]

Sometimes there is an error downloading a dependency - eg. some files are downloaded but the actual JAR is missing from the local Maven repository.
In this case I had to delete the whole folder of the problematic dependency in the local maven repository. Only then did Maven update work (Right-click on the project and select Project > Maven > Update Project.... )

In my case, I had unchecked Build automatically. Checking it again started downloading the jars.

I have come across the same issue recently.
First of all you have to configure proxy settings in settings.xml in your maven repository.
If you are using eclipse/STS then please do verify following.
Window -> Preferences -> Maven -> User Settings -> update user settings by pointing your settings.xml
Now it's set to update the maven project. It worked for me.

I was facing similar sort of issue. I tried deleting folders inside .m2 and again building maven project.
I could download all dependency except one dependency which we have created by ourselves and published on Nexus.
Then I changed by java pointing from JRE to JDK which solved my problem

The following worked for me.
Just right-click on Project -> Maven -> Update Project... such as it is shown here.

I had faced a similar issue and following the below steps helped me fix it.
Delete the last modified jar from respective folders.
Select the project
Right Click -> Maven
Update project..
It will download all the missing Jars.

Try to move your dependencies from "type" tag to "scope" tag like below
or
<dependency>
<groupId>net.xyz.xyz</groupId>
<artifactId>xyz-xyz</artifactId>
<version>x.y.z</version>
<type>pom</type>
</dependency>
or
<dependency>
<groupId>net.xyz.xyz</groupId>
<artifactId>xyz-xyz</artifactId>
<version>x.y.z</version>
<scope>test</scope>
</dependency>
then further Maven > Update Project

For me I changed the packaging from pom to jar, and then the dependency got downloaded.
so I changed from <packaging>pom</packaging> to <packaging>jar</packaging>

Make sure you're defining the dependency as close as possible to the leaf of the project tree where it is needed. Otherwise, Maven might ignore it.
For example, if you have a parent project that references projects A and B and the dependency is with respect to project A, then defining the dependency in the parent's pom.xml might get ignored by Maven. So, define it in project A's pom.xml.
Parent Project's pom.xml
Sub-project A's pom.xml <<< define the dependency where it is needed
Sub-project B's pom.xml

I hope this helps someone as it took me 2 days to realize. I re-imported the project multiple times and followed every possible step I've seen online and in the end I had added a small piece of xml code within the pom.xml. Even though it wasn't erroring or even showing a warning it was preventing maven from reading the lifecycle-mappings.
Click into your pom.xml and go to the dependencies tab on the bottom left, if you see an error there it's likely your pom.xml is corrupted in some way and maven will never attempt to download the dependencies even though you won't get any real error. I had looked back at a previous PR and noticed where/what I added and removed it and was able to get maven to work.

Related

Importing Java owlexplanation libraries in Eclipse [duplicate]

I don't know how to use Maven at all. I've been developing for a couple years with Eclipse and haven't yet needed to know about it. However, now I'm looking at some docs that suggest I do the following:
"To include it within your project, just add this maven dependency to your build."
<repository>
<id>jboss</id>
<url>http://repository.jboss.org/maven2</url>
</repository>
...
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jackson-provider</artifactId>
<version>1.1.GA</version>
</dependency>
How do I do this with my Eclipse project?
Please assume I know nothing about Maven. I just figured out it might be installed on my computer by typing mvn on the command line, but that's seriously the extent of my knowledge. I would be happy to continue knowing nothing about Maven if there is an equivalent, non-Maven way of following these instructions with Eclipse.
On the top menu bar, open Window -> Show View -> Other
In the Show View window, open Maven -> Maven Repositories
In the window that appears, right-click on Global Repositories and select Go Into
Right-click on "central (http://repo.maven.apache.org/maven2)" and select "Rebuild Index"
Note that it will take very long to complete the download!!!
Once indexing is complete, Right-click on the project -> Maven -> Add Dependency and start typing the name of the project you want to import (such as "hibernate").
The search results will auto-fill in the "Search Results" box below.
In fact when you open the pom.xml, you should see 5 tabs in the bottom. Click the pom.xml, and you can type whatever dependencies you want.
You need to be using a Maven plugin for Eclipse in order to do this properly. The m2e plugin is built into the latest version of Eclipse, and does a decent if not perfect job of integrating Maven into the IDE. You will want to create your project as a 'Maven Project'. Alternatively you can import an existing Maven POM into your workspace to automatically create projects. Once you have your Maven project in the IDE, simply open up the POM and add your dependency to it.
Now, if you do not have a Maven plugin for Eclipse, you will need to get the jar(s) for the dependency in question and manually add them as classpath references to your project. This could get unpleasant as you will need not just the top level JAR, but all its dependencies as well.
Basically, I recommend you get a decent Maven plugin for Eclipse and let it handle the dependency management for you.
Open the pom.xml file.
under the project tag add <dependencies> as another tag, and google for the Maven dependencies. I used this to search.
So after getting the dependency create another tag dependency inside <dependencies> tag.
So ultimately it will look something like this.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>doc-examples</groupId>
<artifactId>lambda-java-example</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>lambda-java-example</name>
<dependencies>
<!-- https://mvnrepository.com/artifact/com.amazonaws/aws-lambda-java-core -->
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-core</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
</project>
Hope it helps.
I have faced the similar issue and fixed by copying the missing Jar files in to .M2 Path,
For example: if you see the error message as Missing artifact tws:axis-client:jar:8.7 then you have to download "axis-client-8.7.jar" file and paste the same in to below location will resolve the issue.
C:\Users\UsernameXXX.m2\repository\tws\axis-client\8.7(Paste axis-client-8.7.jar).
finally, right click on project->Maven->Update Project...Thats it.
happy coding.
I have faced same problem with maven dependencies, eg: unfortunetly your maven dependencies deleted from your buildpath,then you people get lot of exceptions,if you follow below process you can easily resolve this issue.

Intellij Idea + Maven: dependency version is wrong in run time

This is driving me crazy. Originally I had added Jackson v. 2.5.4 dependency to my project. Later, I updated it to use 2.6.4 like this:
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.6.4</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.6.4</version>
</dependency>
When writing the code I can see that the new version features are there. Also, when I go to project settings under modules and artifacts everything there says jackson 2.6.4.
But, when I run the program, clearly it's using version 2.5.4. I see that the new feature added in 2.6.0 is not there, also I checked:
System.out.println(ObjectMapper.class.getPackage().getSpecificationVersion());
and the output is 2.5.4...
I rebuilt the project, re-imported dependencies and restarted intellij several times....
please help...
Step 1:
Open the project's folder, then go to : .idea/libraries/ you should find here a file by maven dependency.
Delete the jackson-core and jackson-databinding files.
Step 2: Remove maven dependency
Remove the two dependencies from `pom.xml' file. (do not comment out, erase the lines).
Step 3: Check Intellij project config
Open project structure windows (clic on the top parent folder in Intellij then press F4), then go to Libraries tab. ensure the two dependencies are not present, if there are, delete them as well (with the '-' button at top).
Step 4: Remove all cached maven libraries
Go to your home folder, for windows : C:\Users\<YOUR_NAME>\.m2\, here remove the repository folder.
Step 5: Reimport the project
In intellij : Right click the top folder of your project then > Maven > Reimport.
Step 6: Add maven dep
Add your two dependencies to pom.xml.
Step 8: Build your project.
Launch your project.
This should work.
Run the maven command "mvn dependency:tree" in the directory which contains the parent pomx.mxl file, you can find if you have 2.5.4 there. Maybe you add other jars which also import version 2.5.4, then you should exclude the 2.5.4 version.
Also you can check the local Maven repository, and delete the 2.5.4 version Jackson.
I had a similar issue with one of my dependencies. I went to the .m2/repository directory and manually deleted the unwanted dependencies that were there. I only kept the version I wanted in the m2 directory. Then I invalidated my caches and restarted IntelliJ IDEA. That seemed to have fixed the issue.

maven- not downloading new added dependency in pom.xml file

I need new third party jar for reading csv in maven based project. So, I did entry in pom.xml for same as below.
<dependency>
<groupId>net.sf.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>2.0</version>
</dependency>
But when I run mvn install or mvn package command, It does not download newly added dependency and just build project and generate war.
I am trying to get the issue! Please share solution if anybody face this earlier!
Regards
Try running a forced update:
mvn clean install -U
The -U (uppercase U) forces maven to look at all dependencies and try to update them.
If the dependency is defined in a <dependencies> block that is within a <dependencyManagement> block, adding it without the version number to a <dependencies> block that is outside <dependencyManagement> may fix the problem.
This is because the purpose of <dependencyManagement> block is to manage dependency versions, and not to install the dependencies. See this other article: Differences between dependencyManagement and dependencies in Maven
I resolved this issue by following steps:
1). Remove concerned jar from local /m2 folder.
2). Run mvn eclipse:eclipse command
3). And last run: mvn clean install
Now I am looking for concerned jar in my project class path!
If you are using IntelliJ Idea as your editor then simply follow 3 simple steps:
Right click on your project
Select Maven (last option probably)
Select "Reload project"
And that's it, IntelliJ Idea will download the dependencies and now you can proceed further.
Try:
Menu -> Project -> Clean -> Select the project
Right Click on the project -> Maven -> Maven clean
Right Click on the project -> Maven -> Maven install
Happened to me and it has fixed my problem. Hope it helps you.
I deleted .m2 folder and then from eclipse ran maven install then took maven update project. It resolved my issue and jar file got downloaded.
You can usually resolve these errors by updating Maven dependencies as follows:
Right-click on your top-level project (not on the pom.xml file) in the Project Explorer view.
From the menu, choose Maven > Update project
Make sure ForceUpdate of Snapshots/Releases is checked, and click OK.
You'll see a progress indicator in the lower-right-hand corner of the application window. When the update completes, you should be able to generate code normally, and the error markers should disappear.
In IntelliJ
Right-click on your root folder of the project in the Project Explorer view. From the menu, choose Maven > Reload project.
After that, your new dependencies will be downloaded. Then you should be able to generate code normally, and all the error markers will disappear.

Dependency's Jar not being deployed to Web Project

I've got two Maven projects, A, that generates a jar, and B, that generates a war, in my Eclipse Workspace. A is a dependency of B, and, as such, is in B's POM.
My problem is that A is not being deployed to a .jar in /lib/ when I run a Tomcat server with B.
It seems strange A appears in B's Maven dependencies as a folder, not as jar. Is this anomalous in some manner? If so, how can I fix it?
If this is not the problem, perhaps it's with Tomcat. Do I need to configure it somehow to accommodate this dependency schema (in which the dependency appears as a folder)?
Thanks!
--
EDIT: After manually exporting the .war file of B, I've discovered that A is being put in /lib/ as an empty .ear file.
Here is a screenshot of the dependency been displayed as a folder:
Here are the relevant parts of the POM of A:
<groupId>br.com.reglare</groupId>
<artifactId>rule-model</artifactId>
<packaging>jar</packaging>
<version>1.8</version>
And B:
<dependency>
<groupId>br.com.reglare</groupId>
<artifactId>rule-model</artifactId>
<version>1.8</version>
</dependency>
#urir: Yes, it fails to find a class defined in A: http://990fca173882239e.paste.se/
The dependency should be defined in your pom in this format:
<dependency>
<groupId>xmlbeans</groupId>
<artifactId>xmlpublic</artifactId>
<version>2.2.0</version>
</dependency>
Also to view the dependecy tree use the 'dependency:tree' directive as follows:
mvn clean compile dependency:tree
If the dependecy is still not in the WEB-INF/lib folder of the war, then run the compile with the debugging flag and look for errors:
mvn -X clean compile
Assuming you are using m2e in eclipse to manage the webapp, you need to install m2e-wtp. You should also be able to find it within eclipse in the marketplace. It takes care of making sure that when you launch a maven web project through eclipse it gets all the dependencies in the right place. Once you install the plugin, you may want to delete your project and import it again as an "existing maven project" then the plugin will get it all setup correctly. Applying it after-the-fact has been iffy for me.

Successful build in Maven still showing errors in Eclipse

I'm having something quite peculiar here, my build is successful in maven when I type "mvn clean install" however once imported into Eclipse it's showing errors.
See for yourself:
I guess exluding quartz from the `pom.xml solved the problem but I'd like to know why.
PS: Here is the pom.xml in case you want to see it:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.nantes.mpclient</groupId>
<artifactId>MyClient</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>MyClient</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.nantes.mp</groupId>
<artifactId>MyEjb</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.jboss.jbossas</groupId>
<artifactId>jboss-as-client</artifactId>
<version>5.1.0.GA</version>
<type>pom</type>
</dependency>
</dependencies>
</project>
###EDIT
As you can see quartz is here:
Updating maven project after importing it has fixed this issue for me:
Right click on the project --> Maven --> Update project.
Sometimes I get these types of issues as well.
Generally, what worked best for me with Eclipse & Maven:
Use the latest m2e Eclipse plugin
Use Maven 3
Make sure m2e uses the same Maven version as the one you're using on the command line (not the internal one)
Import projects as Maven projects to generate the Eclipse project files
The other upvoted answers did not work for me using these versions:
Eclipse Neon
Maven 3
m2e 1.7
This is what I had to do:
Delete the Eclipse project from Eclipse interface (do not delete project contents on disk)
Go to the project's root directory in a file explorer or terminal
Delete these files: .classpath, .project, and .settings directory
Back to Eclipse, File -> Import... -> Maven -> Existing Maven projects
If you don't see any error in Eclipse project but it keeps showing the red icon on your project name. Try mvn eclipse:eclipse.
Then select all projects in Eclipse, Right click > Maven > Update projects
Hope it helps.
You should try mvn eclipse:eclipse
And then make sure the M2_REPO variable is point to your local repository.
sometimes maven update nor all above works.
so check which import statement gives you error, then go particular lib file which is usually in c:user/ur-PC-NAME/.m2 get into package delete that .jar file.
then in eclipse, right click on project > maven > update maven.
Sometimes the m2e "maintained" eclipse project is out-of-sync with the actual project in POM (There are lots of reason for that). Assume you have using m2e 0.8 or later, right click on the project, under Maven, there are two entries that are usually useful. They are Update Dependencies and Update Project Configuration
Have a try on them, wait a while after u clicked that for eclipse to update the project and build. Normally it solves similar problems.
That often happens when the m2eclipse hasn't updated the build path to correspond to what a modified POM file says. There's an entry in the Maven context menu to update the Configuration.
In my case,
I just deleted project from Eclipse (not ticked checkbox to delete
from project location).
Opened project as "Existing Maven Project" again.
and it solved my issue.
I found that my project was using a project specific Java Compiler setting set to Java 1.5. Furthermore, the project facets were still referencing Java 1.5 when Maven, m2e, Eclipse general Java Compiler settings were all set to Java 1.8.
In my case there were also problems with Java build path like the following:
"Build path specifies execution environment J2SE-1.5. There are no JREs installed in the workspace that are strictly compatible with this environment." Fixing this resolved compilation errors.
You've a library (quartz-1.5.2.jar) that's reference to your m2 local repository which doesn't exist if you just remove the quartz from your build path and update your dependencies internally(in eclipse) that would solve the problem
Try to use different/older version of JRE. In my case switching back to JRE7 from JRE8 eliminated the problem.
Delete and Re-Import the project in eclipse (without deleting files of course). Unlike other answers I have not looked into why this happens but it works. poof - compilations errors be-gone
It may help: After upgrading eclipse or changing it or something like, old eclipse specific files (.classpath, .project, and .settings) may not be compatible to the new version of eclipse. So you may have to re generate this eclipse specific files using Maven. So try this in your eclipse project root
mvn eclipse:eclipse
In my case, eclipse starts to show all errors after I changed some versions of dependencies in pom.xml, however the command line mvn clean install build successfully
I deleted folders of the dependencies I changed manually from the .m2 repositories (in my case everything under org.apache.beam), because I also has corrupted dependency issues.
mvn clean build the project, this downloaded the dependencies again
right click project: maven -> update project
delete the project from eclipse (but not from disk) and reimport (this actually left me with 1 error still, then i delete and reimported again)
Go to Eclipse> Project (Menu) > Clean... > Select project to clean
This also removes invalid errors from Eclipse.
For me Right click on the project --> Maven --> Update project with the "Force Update of Snapshots/Releases" checkmarked worked.
Some times, eclipse's validation causing these errors.
You can disable them by going to Menu>window>preferences>validation and uncheck suspend all validators or disable them one by one for builds.
E.G, every time You build the project eclipse does not validate your files and does not show up those errors.
This worked for me
Delete the Eclipse project from Eclipse interface (do not delete
project contents on disk)
Go to the project's root directory in a
file explorer or terminal
Delete these files: .classpath, .project,
and .settings directory
Back to Eclipse, File -> Import... -> Maven
-> Existing Maven projects
Got the same problem, I deleted the project from my workspace (not on disk), opened the project folder and deleted the files .project, .classpath and the folder named .settings.
Now goto eclipse again, import the same project again and viola my error is gone!

Categories