Maven : error in opening zip file when running maven - maven

[ERROR] error: error reading C:\Users\suresh\.m2\repository\org\jdom\jdom\1.1\jdom-1.1.jar; error in opening zip file
[ERROR] error: error reading C:\Users\suresh\.m2\repository\javax\servlet\servlet-api\2.5\servlet-api-2.5.jar; error in opening zip file
[ERROR] error: error reading C:\Users\suresh\.m2\repository\org\apache\cxf\cxf-rt-bindings-http\2.2.1\cxf-rt-bindings-http-2.2.1.jar; error in opening zip file
[ERROR] error: error reading C:\Users\suresh\.m2\repository\org\codehaus\jra\jra\1.0-alpha-4\jra-1.0-alpha-4.jar; error in opening zip file
[ERROR] error: error reading C:\Users\suresh\.m2\repository\org\apache\cxf\cxf-api\2.2.1\cxf-api-2.2.1.jar; error in opening zip file
[ERROR] error: error reading C:\Users\suresh\.m2\repository\org\apache\cxf\cxf-common-utilities\2.2.1\cxf-common-utilities-2.2.1.jar; error in opening zip file
[INFO] 44 errors
How to resolve this error while running mvn clean install?
And I see that, starting from servlet-api, no packages are being created inside the local repository on my disk.

Probably, contents of the JAR files in your local .m2 repository are HTML saying "301 Moved Permanently". It seems that mvn does not handle "301 Moved Permanently" properly as expected. In such a case, download the JAR files manually from somewhere (the central repository, for example) and put them into your .m2 repository.
See also:
asm-3.1.jar; error in opening zip file
http://darutk-oboegaki.blogspot.jp/2012/07/asm-31jar-error-in-opening-zip-file.html

This error sometimes occurs. The files becomes corrupt.
A quick solution thats works for me, is:
Go to your local repository (in general /.m2/) in your case I see that is C:\Users\suresh.m2)
Search for the packages that makes conflicts (in general go to repository/org) and delete it
Try again to install it
With that you force to get the actual files
good luck with that!

Try to remove your repository in /.m2/repository/ and then do a mvn clean install to download the files again.

I had the same problem but previous solutions not work for me. The only solution works for me is the following URL.
https://enlightensoft.wordpress.com/2013/01/15/maven-error-reading-error-in-opening-zip-file/
[EDIT]
Here I explain more about it
Suppose you got an error like below
[ERROR] error: error reading C:\Users\user\.m2\repository\org\jdom\jdom\1.1\jdom-1.1.jar; error in opening zip file
Then you have to follow these steps.
First, delete the existing jar C:\Users\user\.m2\repository\org\jdom\jdom\1.1\jdom-1.1.jar
Then you have to manually download relevant jar from Maven central repository. You can download from this link here
After that, you have to copy that downloaded jar into the previous directory.C:\Users\user\.m2\repository\org\jdom\jdom\1.1\
Then you can build your project using mvn clean install
hope this will help somebody.

go to the .m2/repository and delete the conflicting files
mvn -U clean install

This error can occur when your connection gets interrupted during your dependencies are being downloaded.
Delete the relevant repository folder and run following command again to download a fresh copy of corrupted file.
mvn clean install

I just have this error. You can delete the files and run the compiling command again:
$ sudo rm /Users/Chaklader/.m2/repository/org/apache/poi/poi/3.17/poi-3.17.jar
$ sudo rm /Users/Chaklader/.m2/repository/com/fasterxml/jackson/core/jackson-databind/2.7.5/jackson-databind-2.7.5.jar
$ sudo rm /Users/Chaklader/.m2/repository/com/fasterxml/jackson/core/jackson-core/2.7.5/jackson-core-2.7.5.jar
Now, run the command for the clean compile:
$ mvn -U clean compile

I had a similar problem as well. The fix was a mix of both. I had a problem with asm-3.1 (as mentioned in the blog post linked by Takahiko. That jar was corrupt. I needed to manually get the jar from the maven central repository. Removing it and retrying just got the corrupt jar again. It then still failed on the asm-parent, which was a POM file containing the HTML with a 301. Again, it required manually getting the file myself. You may want to check what settings XML to see if you're set to a different repository, such as a local nexus server.
When the proper way to get the new one fails, manually grab it yourself.

I deleted the jar downloaded by maven
manually download the jar from google
place the jar in the local repo in place of deleted jar.
This resolved my problem.
Hope it helps

I also encountered the same problem, my problem has been resolved.
The solution is:
According to error information being given, to find the corresponding jar in maven repository and deleted.
Then executed mvn install command after deleting.

Accidently I found a simple workaroud to this issue. Running Maven with -X option forces it to try other servers to download source code. Instead of trash HTML inside some jar files there is correct content.
mvn clean install -X > d:\log.txt
And in the log file you find messages like these:
Downloading: https://repository.apache.org/content/groups/public/org/apache/axis2/mex/1.6.1-wso2v2/mex-1.6.1-wso2v2-impl.jar
[DEBUG] Writing resolution tracking file D:\wso2_local_repository\org\apache\axis2\mex\1.6.1-wso2v2\mex-1.6.1-wso2v2-impl.jar.lastUpdated
Downloading: http://maven.wso2.org/nexus/content/groups/wso2-public/org/apache/axis2/mex/1.6.1-wso2v2/mex-1.6.1-wso2v2-impl.jar
You see, Maven switched repository.apache.org to maven.wso2.org when it encountered a download problem. So the following error is now gone:
[ERROR] error: error reading D:\wso2_local_repository\org\apache\axis2\mex\1.6.1-wso2v2\mex-1.6.1-wso2v2-impl.jar; error in opening zip file

This issue is a pain in my a$$, I have this issue in my Mac,
if I run
mvn clean install | grep "error reading"
[ERROR] error reading /Users/ducnguyen/.m2/repository/org/apache/velocity/velocity/1.7/velocity-1.7.jar; error in opening zip file
[ERROR] error reading /Users/ducnguyen/.m2/repository/commons-net/commons-net/3.3/commons-net-3.3.jar; error in opening zip file
[ERROR] error reading /Users/ducnguyen/.m2/repository/org/apache/commons/commons-lang3/3.0/commons-lang3-3.0.jar; error in opening zip file
[ERROR] error reading /Users/ducnguyen/.m2/repository/org/bouncycastle/bcprov-jdk15on/1.54/bcprov-jdk15on-1.54.jar; error in opening zip file
[ERROR] error reading /Users/ducnguyen/.m2/repository/javax/mail/mail/1.4/mail-1.4.jar; error in opening zip file
[ERROR] error reading /Users/ducnguyen/.m2/repository/org/apache/pdfbox/pdfbox/2.0.0/pdfbox-2.0.0.jar; error in opening zip file
[ERROR] error reading /Users/ducnguyen/.m2/repository/com/itextpdf/itextpdf/5.5.10/itextpdf-5.5.10.jar; error in opening zip file
[ERROR] error reading /Users/ducnguyen/.m2/repository/org/slf4j/slf4j-api/1.7.24/slf4j-api-1.7.24.jar; error in opening zip file
[ERROR] error reading /Users/ducnguyen/.m2/repository/com/aspose/aspose-pdf/11.5.0/aspose-pdf-11.5.0.jar; error in opening zip file
[ERROR] error reading /Users/ducnguyen/.m2/repository/org/apache/velocity/velocity/1.7/velocity-1.7.jar; error in opening zip file
[ERROR] error reading /Users/ducnguyen/.m2/repository/commons-net/commons-net/3.3/commons-net-3.3.jar; error in opening zip file
[ERROR] error reading /Users/ducnguyen/.m2/repository/org/apache/commons/commons-lang3/3.0/commons-lang3-3.0.jar; error in opening zip file
[ERROR] error reading /Users/ducnguyen/.m2/repository/org/bouncycastle/bcprov-jdk15on/1.54/bcprov-jdk15on-1.54.jar; error in opening zip file
[ERROR] error reading /Users/ducnguyen/.m2/repository/javax/mail/mail/1.4/mail-1.4.jar; error in opening zip file
[ERROR] error reading /Users/ducnguyen/.m2/repository/org/apache/pdfbox/pdfbox/2.0.0/pdfbox-2.0.0.jar; error in opening zip file
[ERROR] error reading /Users/ducnguyen/.m2/repository/com/itextpdf/itextpdf/5.5.10/itextpdf-5.5.10.jar; error in opening zip file
[ERROR] error reading /Users/ducnguyen/.m2/repository/org/slf4j/slf4j-api/1.7.24/slf4j-api-1.7.24.jar; error in opening zip file
Removing all corrupted libs is the only solution
So I want to remove all of them at once.
mvn clean install | grep "error reading" | awk '{print "rm " $4 | "/bin/sh" }'
The command needs AWK to take libPath string from column $4
Then rerun
mvn clean install

I deleted the affected jar file from Maven external libraries
Then I performed Maven > Reload project which fixed the library by reinstalling
This worked for me without manually downloading a .jar file

For me I should change the .m2 repo in the settings.xml file with another one because in Mac maven can't create a folder that start with point(.)
to solve that, open your maven/version/conf/settings.xml and specify the location of your repo folder like this :
<localRepository>../repo</localRepository>
don't forget to change it also in your IDE, in eclipse go to : Windows > Preferences > Maven > User Settings > Global Settings, and navigate to your settings.xml.
clean install your project.
hope this will help you.

This error occurs because of some file corruption.
But we don't need to delete whole .m2 folder.
Instead find which jar files get corrupted by looking at the error message in the console. And delete only the folders which contains those jar files.
Like in the question :
C:\Users\suresh\.m2\repository\org\jdom\jdom\
C:\Users\suresh\.m2\repository\javax\servlet\servlet-api\
C:\Users\suresh\.m2\repository\org\apache\cxf\cxf-rt-bindings-http
C:\Users\suresh\.m2\repository\org\codehaus\jra\jra
C:\Users\suresh\.m2\repository\org\apache\cxf\cxf-api
C:\Users\suresh\.m2\repository\org\apache\cxf\cxf-common-utilities
Delete these folders.
Then run.
mvn clean install -U

Deleting the entire local m2 repo may not be advisable. As in my case I have hundreds and hundreds of jars in my local, I don't want to re-download them all just for one jar.
Most of the above answers didn't work for me, here is what I did.
STEP:1: Ensure if you are downloading from the correct Maven repo in you settings.xml. In my case it was referring to http://central.maven.org/maven2/ as https://repo1.maven.org/maven2/. So it was getting corrupted or going otherwise?
STEP:2: Delete the folder containing the artifact and other details in your local machine.This will force it download it again upon next build
STEP:3: mvn clean install :).
Hope it helps.

I downloaded the jar file manually and replace the one in my local directory and it worked

You could also check if the required certificates are installed to make sure that it allows the dependencies to be downloaded.

Related

Gradle Could not expand ZIP: is not a ZIP archive

I am trying to unzip an archive file in my Gradle build script.
The archive file exists, and I have checked that it is indeed a zip file by running
file myfile.zip
However, build fails with the following error:
Could not expand ZIP '/.../file.zip': is not a ZIP archive
For Windows:
Please delete the package of the zip file and clean gradle. It will resolve.
One reason this can happen is if the file is damaged or corrupted.
The way to check that is to try manually unzipping the file.
For me, the problem was semi-unrelated. My build directory was owned by root and I was running as a user that did not have permissions to write there. I ended up deleting the dir and the next gradle build handled it.
Yes.. it was due to permission on that file.
For windows:
Give the permission including parent folder as same administrator.
Try it to do it again.
If still not work, delete the zip file and let them create again after 1st step. It will resolve.
I got same error, and after running ./gradlew build --stacktrace found out that resources folder contained Flyway migration file with name "V1.1.98__documents..sql" (double dot). Apparently this caused problems with zipping. Was typo of course.

How to resolve "test-life cycle-and-artifact Handler1.pom.sha1 " cannot creat on maven installiton

I need your help.
I downloaded maven 3-5-0-src.zip file from maven site. I started to unzip process after a few seconds I got an this error.
Error: System doesn't find this path.
Cannot create
C:\Users\AppData\Local\Temp\wz85b2\apache-maven-3.5.0\maven-core\src\test\resources\org\apache\maven\extension\test-extension-repo\org\apache\maven\core\test\test-lifecycle-and-artifactHandler\1\test-lifecycle-and-artifactHandler-1.pom.sha1.
I can't install maven on my computer. How can solve this?
The ...-src.zip file only contains the source files for your reference.
You need to download and install the binary zip file at apache-maven-3.5.0-bin.zip if you're planning to use maven to build stuff.
Otherwise, the above error looks suspiciously like a Windows path length problem.

Jenkins/Maven build test failure

When I ran maven project from my terminal it works fine but when I ran the same test using Jenkins job it failed giving the following error :
Error Message
/build-nas/jenkins/jenkins163/workspace/Gitrepo/MAVEN/TestConfig.properties
(No such file or directory).
I see that the file is present in the workspace and I am using Git repo where I can see the file named TestConfig.properties present. Please advise. Thank you for the help.

Maven : pom.lastUpdated exists but no jar [duplicate]

I have an Eclipse setup with m2eclipse and subversive. I have imported a maven2 project from svn. But I get the error message that a whole bunch of artifacts are missing (for instance: Missing artifact org.springframework:spring-test:jar:3.0.1.RELEASE:test).
If I look in my repository I see the jar files there but they have an extra extension .lastUpdated. Why is maven appending .lastUpdated to the jars? And more importantly: how can I fix this?
There is no mention of the type lastUpdated in my POMs.
These files indicate to Maven that it attempted to obtain the archive by download, but was unsuccessful. In order to save bandwidth it will not attempt this again until a certain time period encoded in the file has elapsed. The command line switch -U force maven to perform the update before the retry period. This may be necessary if you attempted to build while disconnected from the network.
The method of removing the files works with most versions of maven, but since the files are internal mementos to maven, I would not recommend this method. There is no guarantee that this information is not referenced or held elsewhere and such manipulation can damage the system.
As rperez said, I use to delete all those .lastUpdated files. In Linux I have created a little script to keep it simple:
find -name \*.lastUpdated -exec rm -fv {} +
Just create a file with the previous content and put it on your local Maven repository. Usually it will be ~/.m2/repository.
I installed Maven2 and ran mvn compile from the command line. This seems to have resolved the problem
you might have a problem with some of the artifacts to be retrieved from the repository. for example spring framework has its own repository. this xtension is appended when the artifact cannot fully downloaded. add the spring framework repository to your pom or settings.xml, delete the folder that include the broken jars and start again
If you hit this problem and you're using Nexus, it might be the case that you have a routing rule defined, which is incorrect. I hit this myself and the files it was downloading were correctly named, at the proper URL-s it was looking at, but they were all with the .lastUpdated extension and an error message as contents.
Open your terminal, navigate to your Eclipse's project directory and run:
mvn install
If mvn install doesn't update your dependencies, then call it with a switch to force update:
mvn install -U
This is a much safer approach compared to tampering with maven files as you delete ".lastUpdated".
Use this command inside the .m2/repository dir to rename all files:
for file in `find . -iname *.lastUpdated`; do renamed=$(echo $file | rev | cut -c13- | rev); echo renaming: $file to $renamed; mv $file $renamed; done
This is usefull to not download all sources again.
This not work... The .jar is lost. :(
What I do when I encounter this issue:
Make sure you have the version of the latest 'maven-source-plugin' plugin:
https://maven.apache.org/plugins/maven-source-plugin/usage.html
$ mvn source:jar install
Now if the file *.lastUpdate exist in your local ~/.m2/repositories/your-lib/0.0.1/ directory you can just remove it then run the command above again.
This is a side-effect of a failure to successfully extract from the repository. To get the actual content you want into your repository, check for correct paths to the repository/repositories within your pom file, and resolve certificate/security issues, if any. It is almost invariably one or the other of these issues.
There is no need to delete the .lastUpdated entries, and doing so won't solve your problem.

Liferay theme development using JBoss on Mac

I am creating liferay themes using JBoss on my Mac. In the process of creating a theme, when I execute ant deploy on my terminal, I am getting following errors:
Buildfile:
/Users/saif/Desktop/Liferay/liferay-plugins-sdk-6.1.1/themes/g2y-b2b-theme/build.xml
[copy] Copying 1 file to /usr/share/ant/lib
BUILD FAILED
/Users/saif/Desktop/Liferay/liferay-plugins-sdk-6.1.1/themes/g2y-b2b-theme/build.xml:5:
The following error occurred while executing this line:
/Users/saif/Desktop/Liferay/liferay-plugins-sdk-6.1.1/themes/build-common-theme.xml:7:
The following error occurred while executing this line:
/Users/saif/Desktop/Liferay/liferay-plugins-sdk-6.1.1/build-common-plugin.xml:5:
The following error occurred while executing this line:
/Users/saif/Desktop/Liferay/liferay-plugins-sdk-6.1.1/build-common.xml:68:
Failed to copy
/Users/saif/Desktop/Liferay/liferay-plugins-sdk-6.1.1/lib/ecj.jar to
/usr/share/ant/lib/ecj.jar due to java.io.FileNotFoundException
/usr/share/ant/lib/ecj.jar (Permission denied)
Total time: 0 seconds
Please help me to get rid of this and proceed further. What are the steps I should take in order to do this on a Mac? Please also tell me how to set up the environment variable of ANT on a Mac.
When ant builds your theme and requires ecj.jar (the eclipse compiler for java) it typically downloads it from some internet repository and places it in $ANT_HOME/lib. It seems your $ANT_HOME is usr/share/ant and you don't have write access to that directory. Either download it manually and place it there or open up the directory write permissions for one build (then close it again).
You'll only need to do this once: When ecj.jar is on the classpath for ant, it will just be used for eternity.

Resources