Maven failing to download jar dependencies - java

I have a very simple default application that I've created to test my Eclipse Indigo/Maven v3.0.1 setup on my Windows 7 machine. The Hello World app runs fine from Eclipse.
Now from the command line I'm trying to test with mvn install.
At which point I see Maven download a large series of dependencies. For some reason though it will get stuck downloading one and will just stop part way through. It's not at the same point each time, but it's currently consistently the same jar file, eg...
http://repo1.maven.org/maven2/org/apache/maven/surefire/surefire-booter/2.5/surefire-booter-2.5.jar
If I download this file from a browser it works perfectly. Quite fast in fact. Now if I manually copy that downloaded file to the appropriate directory in my .m2 repository directory, the install continues to download dependencies until it hits another one at random which it stops at.
Here's my POM, although I'm not sure it'll help as it's so basic and seems to work fine with a mvn compile.
<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.kyeema</groupId>
<artifactId>QServer</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>QServer</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>
</dependencies>
</project>
Here's some debug output referencing some dummy jar file?
[INFO] Surefire report directory: C:\workspace\QServer\target\surefire-reports
[DEBUG] Setting system property [user.dir]=[C:\workspace\QServer]
[DEBUG] Setting system property [localRepository]=[C:\Users\Andre\.m2\repository]
[DEBUG] Setting system property [basedir]=[C:\workspace\QServer]
[DEBUG] Using JVM: C:\Program Files\Java\jdk1.7.0\jre\bin\java
[DEBUG] dummy:dummy:jar:1.0 (selected for null)
[DEBUG] org.apache.maven.surefire:surefire-booter:jar:2.7.2:compile (selected for compile)
[DEBUG] org.apache.maven.surefire:surefire-api:jar:2.7.2:compile (selected for compile)
[DEBUG] Adding to surefire booter test classpath: C:\Users\Andre\.m2\repository\org\apache\maven\surefire\surefire-booter\2.7.2\surefire-booter-2.7.2.jar Scope: compile
[DEBUG] Adding to surefire booter test classpath: C:\Users\Andre\.m2\repository\org\apache\maven\surefire\surefire-api\2.7.2\surefire-api-2.7.2.jar Scope: compile
[DEBUG] dummy:dummy:jar:1.0 (selected for null)
[WARNING] Missing POM for org.apache.maven.surefire:surefire-junit3:jar:2.7.2: Error resolving project artifact: Failure to find org.apache.maven.surefire:surefire-junit3:pom:2.7.2 in http://mirrors.ibiblio.org/pub/mirrors/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of ibiblio.org has elapsed or updates are forced for project org.apache.maven.surefire:surefire-junit3:pom:2.7.2
[DEBUG] org.apache.maven.surefire:surefire-junit3:jar:2.7.2:test (selected for test)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.626s
[INFO] Finished at: Tue Aug 16 13:18:42 PDT 2011
[INFO] Final Memory: 8M/154M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.7.2:test (default-test) on project QServer: Error to resolving surefire provider dependency: Missing:
[ERROR] ----------
[ERROR] 1) org.apache.maven.surefire:surefire-junit3:jar:2.7.2
[ERROR]
[ERROR] Try downloading the file manually from the project website.
[ERROR]
[ERROR] Then, install it using the command:
[ERROR] mvn install:install-file -DgroupId=org.apache.maven.surefire -DartifactId=surefire-junit3 -Dversion=2.7.2 -Dpackaging=jar -Dfile=/path/to/file
[ERROR]
[ERROR] Alternatively, if you host your own repository you can deploy the file there:
[ERROR] mvn deploy:deploy-file -DgroupId=org.apache.maven.surefire -DartifactId=surefire-junit3 -Dversion=2.7.2 -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]
[ERROR]
[ERROR] Path to dependency:
[ERROR] 1) dummy:dummy:jar:1.0
[ERROR] 2) org.apache.maven.surefire:surefire-junit3:jar:2.7.2
[ERROR]
[ERROR] ----------
[ERROR] 1 required artifact is missing.
[ERROR]
[ERROR] for artifact:
[ERROR] dummy:dummy:jar:1.0
[ERROR]
[ERROR] from the specified remote repositories:
[ERROR] ibiblio.org (http://mirrors.ibiblio.org/pub/mirrors/maven2, releases=true, snapshots=false)

OK guys, I had the same problem downloading a large file. We're all probably using the lightweight HTTP wagon. If you look at the docs:
http://maven.apache.org/wagon/wagon-providers/wagon-http-lightweight/
Known Limitation:
The main limitation is that you can't download data that doesn't fit entirely into memory.
So I increased the memory for Maven:
export MAVEN_OPTS="-Xmx1024m"
and voila, it works. (!!!!)

I had the same problem. In my case AVG antivirus software blocked Maven from downloading artifacts. Disabling it temporarily helped.

Well for what it's worth, here's the answer to what I've been experiencing.
If I leave Maven at v3.0.1 I have to add the mirror listed above and it works fine.
If I upgrade Maven to v3.0.3 then I have to remove the mirror listed above to make it work. :-)
I tried this on two separate machines and had identical behaviour. This could mean the network here is to blame as they both go through the same router.
Anyway, so there's essentially two workarounds there. I'm not sure if either are the "correct" response, but they keep me moving forward at least.
Thanks to all that submitted answers.

I solved this problem by downgrading to Java 6.

In my case, I went to the local repository (~/.m2/repository/), found the corresponding group and discovered that the artifact at which the download is stuck has two files with .part and .part.lock extensions. Deleting them helped.

I had exactly the same problem a while back - long story short it was a networking issue. And, yes just like you tried I could grab the file with a web browser just fine.
For testing purposes are you using a proxy, and to the proxy settings in Maven match the browser?

I had similar issue. What changed was the move of nexus to VPN. Turned out I had DNS entry cached.
Flushing DNS fixed it. For record for Ubuntu like systems:
sudo systemd-resolve --flush-caches

Related

Cannot resolve com.sun:tools:0 in Maven Project?

I've been working with test automation a lot lately.
Im now familiarized with several tools, frameworks, dependencies, etc. like Selenium, JUNits, TestNG that helps me manage my daily work as a QA Engineer.
I frequently use Selenium and TestNG to build up my solutions, together with IntelliJ IDEA that runs on the latest JDK version (jdk-15.0.1) available on a Mac running on macOs Catalina Version 10.15.7.
I have mi POM.mxl file already configured for my projects and since the very beginning it displayed the following error on the console:
Cannot resolve com.sun:tools:0
I always ignored that because my projects within my IDE always compiled&ran and because I was never using that dependency. But now I'm trying to run my project with maven support from my Terminal in my Mac and because of the sun:tools.jar dependency, I'm not allowed to compile any working project I have developed so far.
I have read a lot of similar threads on similar problems with the same sun:tools:jar dependency like in:
Missing artifact com.sun:tools:jar
Missing Library com.sun.tools.attach
Could not find artifact com.sun:tools:jar:0
I have done everything, but many solutions were based on finding the tools.jar file in the jdk installation directory. Since I'm using JDK 15, this dependency was already removed:
Removed: rt.jar and tools.jar
The class and resource files previously stored in lib/rt.jar,
lib/tools.jar, lib/dt.jar, and various other internal JAR files are
now stored in a more efficient format in implementation-specific files
in the lib directory. The format of these files is not specified and
is subject to change without notice.
I attach the exact error message I get with the terminal:
----------------------< org.example:YelpExercise >----------------------
[INFO] Building YelpExercise 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.737 s
[INFO] Finished at: 2020-11-04T18:59:47-03:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project YelpExercise: Could not resolve dependencies for project org.example:YelpExercise:jar:1.0-SNAPSHOT: Could not find artifact com.sun:tools:jar:0 at specified path /Library/Java/JavaVirtualMachines/jdk-15.0.1.jdk/Contents/Home/../lib/tools.jar -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
Ok, after hours and even days of research, I found the solution:
For JDK 9 and above, when defining the pom.xml, you have to exclude that sub-dependency whenever you will use a dependency that contains it. In my case, the cobertura dependency included sun.com:tools.
What I edited in my pom.xml file:
<!-- https://mvnrepository.com/artifact/net.sourceforge.cobertura/cobertura -->
<dependency>
<groupId>net.sourceforge.cobertura</groupId>
<artifactId>cobertura</artifactId>
<version>2.1.1</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
</exclusion>
</exclusions>
</dependency>
This seems to be still an open issue for some maven dependencies. Check: issues1 or issues2 or Google search: <dependency_you_are_using> sun tools for more info.

Maven fails to find io.reactivex.subjects in terminal, succeeds in Eclipse

In attempting to prepare a personal project for Gitlab CI, I've stumbled across an issue where maven cannot find the io.reactivex.subjects package in the terminal, and as a result, compilation fails like so:
[INFO] --- maven-compiler-plugin:3.7.0:compile (default-compile) # spell-idle ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 24 source files to /home/aschaefer/dev/spell-idle/target/classes
...
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project spell-idle: Compilation failure: Compilation failure:
[ERROR] /home/aschaefer/dev/spell-idle/src/com/aps/spells/rx/GuiSubjects.java:[5,29] package io.reactivex.subjects does not exist
[ERROR] /home/aschaefer/dev/spell-idle/src/com/aps/spells/rx/GuiSubjects.java:[6,29] package io.reactivex.subjects does not exist
[ERROR] /home/aschaefer/dev/spell-idle/src/com/aps/spells/rx/GuiSubjects.java:[14,29] cannot find symbol
[ERROR] symbol: class Subject
[ERROR] location: class com.aps.spells.rx.GuiSubjects
[ERROR] /home/aschaefer/dev/spell-idle/src/com/aps/spells/rx
Here's the arguably relevant part of the pom. If anything else is needed, let me know and I'll edit it in:
<dependencies>
<dependency>
<groupId>io.reactivex.rxjava2</groupId>
<artifactId>rxjavafx</artifactId>
<version>2.2.2</version>
</dependency>
... (other dependencies here)
</dependencies>
I've been running various combinations of commands like mvn clean install or mvn compile test but it doesn't seem to help.
Eclipse version of maven is 3.5.3, system version is 3.5.2.
I don't have a settings.xml in the ~/.m2 directory.
Thanks in advance for any help offered!
As you say that in eclipse is working, go to Preferences>Maven>user settings there you will see the eclipse mvn configuration and compare it with the one on your system normally in ~/.m2/settings.xml or by the environment variable $M2_HOME/conf/settings.xml

Maven, lost local dependency | Could not resolve dependencies for project

Hi guys I have a Maven project working well since 9 months.
But today I get a error in Maven build
[ERROR] Failed to execute goal on project bon: Could not resolve dependencies for project com.mydev:bon:war:1.0.20.1: Failure to find com.mydev:utils:jar:1.0.0-BUILD-SNAPSHOT in http://repo1.maven.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of maven2 has elapsed or updates are forced -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
The project is a Dynamic Web Project with maven
In pom I have a dependency to local jar
<dependency>
<groupId>com.mydev</groupId>
<artifactId>utils</artifactId>
<version>1.0.0-BUILD-SNAPSHOT</version>
</dependency>
The project com.mydev.utils has installed in my PC in .m2 folder, I check the folder D:\.m2\repository\com\mydev\utils\1.0.0-BUILD-SNAPSHOT\ and everything seems in order
_rzi_0.118
_rzi_0.227
_maven.repositories
utils-1.0.0-BUILD-SNAPSHOT.jar
utils-1.0.0-BUILD-SNAPSHOT.jar.lastUpdate
utils-1.0.0-BUILD-SNAPSHOT.pom
utils-1.0.0-BUILD-SNAPSHOT.pom.lastUpdate
m2e.lastUpdate.properties
maven-metadata-local.xml
resolver-status.properties
I do not think the problem is the pom, I have not changed anything
I tried to build another project with the same unit, and get the same error.
I install software yesterday (DB2 Express-C database server), not if maven may have lost some settings for it. wheninstall the software, do not restart
Today try to generate the war, but I get the error, I reboot the PC, but I have the same error
Edit:
One more thing you do not need to do copy and paste thing , you can just easily modify your maven setting.xml for maven repo and in eclipse point it to correct file. In above scree shot user setting path should be you maven installation dir like <your dir>\apache-maven-xxx\conf\settings.xml
settings.xml
<localRepository>D:\.m2</localRepository>

Failed build in Jenkins: cannot resolve sqljdbc4 jar

I have started configuring Jenkins with my project. I made sure to install the sqljdbc driver in my local repository first:
$>mvn install:install-file -Dfile=sqljdbc4-4.0.jar
-DgroupId=com.microsoft.sqlserver -DartifactId=sqljdbc4 -Dversion=4.0 -Dpackaging=jar
I can see the jar has apparently been installed successfully at:
C:\Users\ me \.m2\repository\com\microsoft\sqlserver\sqljdbc4\4.0
This is what the pom relevant parts looks like:
<sqljdbc4.version>4.0</sqljdbc4.version>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc4</artifactId>
<version>${sqljdbc4.version}</version>
</dependency>
However when I try to build the project from jenkins I get:
Executing Maven: -B -f C:\Program Files (x86)\Jenkins\jobs\Build Solutions Project\workspace\pom.xml install
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building CommonFrontPage 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
Downloading: http://repo.maven.apache.org/maven2/com/microsoft/sqlserver/sqljdbc4/4.0/sqljdbc4-4.0.pom
[WARNING] The POM for com.microsoft.sqlserver:sqljdbc4:jar:4.0 is missing, no dependency information available
I'm not sure why it's not looking in my local repository first.
I also set under "configure" > "Maven Project Configuration":
Local Maven Repository Default (~/.m2/repository)
I restarted the Jenkins service too.
I am not sure how to proceed from here.
I know I could use nexus, but I don't really need it at this stage.
Maven version: 3.0.5
I managed to solve it. Since it was building correctly checking out the repository and using maven from the command line, I figured Jenkins was using a different configuration to resolve the repository, so I explicitly added:
C:/Users/me/.m2/repository
into maven's "setting.xml".
Not sure if it's the most elegant solution but at least it works now.

Problems after Maven installation - mvn install tries to download unreachable files

After installing maven (mvn -v works fine), I tried to do mvn install in a directory having a good pom.xml at the root of a Maven project that I know works.
I get the output shown at the bottom which basically states that it tried to download a file from an online maven repository and failed. The file appears to be maven-oriented and I don't think it's related to my project.
In addition, if I run mvn install in a directory without a pom.xml, which should just fail as I understand it, I get the same problems. I'm guessing my Maven just hasn't been fully set up yet and its configuring itself maybe?
Can anyone tell me why it wants these files, and why it might be failing?
I seem to have access to the URL in chrome and the file being targeted is there, so even if it does need it, I'm baffled about why the download is failing.
C:\>mvn install
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Default Project
[INFO] task-segment: [install]
[INFO] ------------------------------------------------------------------------
Downloading: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-resources-plugin/2.3/maven-resources-plugin-2.3.pom
[WARNING] Unable to get resource 'org.apache.maven.plugins:maven-resources-plugin:pom:2.3' from repository central (http://repo1.maven.org/maven2): Error transferring file: Connection timed out: conne
ct
Downloading: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-resources-plugin/2.3/maven-resources-plugin-2.3.pom
[WARNING] Unable to get resource 'org.apache.maven.plugins:maven-resources-plugin:pom:2.3' from repository central (http://repo1.maven.org/maven2): Error transferring file: Connection timed out: conne
ct
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Error building POM (may not be this project's POM).
Project ID: org.apache.maven.plugins:maven-resources-plugin
Reason: POM 'org.apache.maven.plugins:maven-resources-plugin' not found in repository: Unable to download the artifact from any repository
org.apache.maven.plugins:maven-resources-plugin:pom:2.3
from the specified remote repositories:
central (http://repo1.maven.org/maven2)
for project org.apache.maven.plugins:maven-resources-plugin
Your gateway is blocking maven from downloading the dependencies.
Try and check whether you are able to download this pom file manually.
http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-resources-plugin/2.3/maven-resources-plugin-2.3.pom
if you are open the above URL from your browser, then check your firewall settings(Sometimes firewall settings also block maven from downloading the dependencies, especially if you are in an enterprise environment).
if that is the case, you need to use a proxy to bypass your gateway and download the dependencies
OR
Download the plugins manually from maven central or nexus repository and install it using maven install command in your local .m2 directory.
maven install -DartifactId="your dependency" -DgroupId="groupID of the
dependency" -DFile="your file location"
As you mentioned in the comments that you are able to open the site from chrome, you can install the dependency using the above command.
Unable to download the artifact from any repository maven:
Check for proxy :if you have some customized jar file related to your company project ,it needs your firewall and if you are using any proxy in setting.xml file then block it to get it downloaded.

Categories