Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wget not working to download jar file from maven repo

I'm trying to download a single jar file from the maven repository, from the URL below.

http://repo1.maven.org/maven2/com/google/guava/guava-testlib/10.0/guava-testlib-10.0.jar

  • Downloading in a browser works fine, and I get the file as expected.

  • 'wget' downloads something, but the file I get doesn't appear to be valid. Running 'jar -tf' on the downloaded file gives 'ZipException: error in opening zip file'.

  • Downloading the file programmatically from Java ('InputStream' from the URL writing to a 'FileOutputStream') downloads something and creates the file. Opening that with WinZip/7-Zip, it appears to contain one file named 'guava-testlib-10.0', which looks like the jar archive I was expecting to get.

  • wget another jar does work as expected at least sometimes (with -U user agent string)

Is this some dodgy interaction between wget/maven or Java/maven? Is it a malformed jar file that my browser understands and downloads correctly? Both of those seem slightly implausible to me.

like image 309
Joe Kearney Avatar asked Sep 29 '11 10:09

Joe Kearney


People also ask

How do I download a maven repository jar?

Download Jar From maven.org. There is another maven repository that you can download jar files from. Open a web browser and browse the URL maven.org or search.maven.org. Input the jar library group name or artifact name in the search box, it will list all matched jar libraries.

How do I download files from wget?

Downloading a file In order to download a file using Wget, type wget followed by the URL of the file that you wish to download. Wget will download the file in the given URL and save it in the current directory.


1 Answers

wget generally gets blocked from the central maven repo because some people don't play nice and try to wget too much. Try set the user agent:

wget -U "Any User Agent" http://repo1.maven.org/maven2/com/google/guava/guava-testlib/10.0/guava-testlib-10.0.jar
like image 190
leonm Avatar answered Nov 15 '22 15:11

leonm