Aniket Thakur
Aniket Thakur

Reputation: 68915

archive for required library could not be read or is not a valid ZIP file

Before coming to the problem let me explain what I did that has landed me in the problem.

  1. I created an account on github and made a repository named Android.
  2. Then I installed github client in my windows 7.
  3. Then I opened this client, provided my authentication and cloned the repository to a local directory C:\Users\Aniket\Documents\GitHub\Android(This folder has the .git folder in it).
  4. Then I went to my Eclipse ADT and installed EGit plugin as described here. Also I
  5. Then in Eclipse I right click on my project TicTacToe go to Team->Share Project and provide my repository path i.e C:\Users\Aniket\Documents\GitHub\Android.
  6. My Project was added to the local repository and in my github client it shows me all option to commit file in the actual repository on the github site.
  7. But my project is suddenly showing error with a red '!' sign on it.

    Description --> Archive for required library: 'C:/Users/Aniket/AndroidWorkspace/TicTacToe /libs/android-support-v4.jar' in project 'TicTacToe' cannot be read or is not a valid ZIP file

    Resource --> TicTacToe

    Path Location --> Build path

    Type --> Build Path Problem

Note : the Error was a single line displayed in error console on Eclipse. I just split it up for readability.

Even after detaching repository it shows that error.

Has anyone encountered this scenario before. What is the solution or workaround? I googled and first few links suggest it is an Eclipse bug. Please suggest what can be done to bring my project back to executable state?

Upvotes: 29

Views: 74422

Answers (18)

Micha Herrmann
Micha Herrmann

Reputation: 71

I had accidentally put the web.xml into the build path :x

Upvotes: 0

Asher
Asher

Reputation: 102

I realize this is an old question, but I have yet another solution if none of these work for other people coming across this thread. I had this same problem, and spent alot of time trying to figure it out, only to find that my Eclipse classpath/buildpath has a .json file in it, it doesn't like that, so it wouldn't compile. So, check to make sure no text files or json files, etc are in your build path.

Upvotes: 0

rachit
rachit

Reputation: 1996

It is an Eclipse bug. I have faced the similar problem several times. closing and reopening the project works sometime. if it doesn't work try restarting Eclipse.

Upvotes: 49

Andy Kofi
Andy Kofi

Reputation: 9

I was stacked on this problem for days despite searching for a solution on the net. I first moved my project to Netbeans and all worked fine. I then returned to eclipse->properties->java compile-> Building and changed "Incompartible build path" option from error to warning and then did maven update and it worked.

Upvotes: 0

duderoot
duderoot

Reputation: 987

I will say that it can be that some answers work for some cases, but for me it was necessary to go an extra mile. So I will try to make a summary of what can be done:

  1. Verify that the jars are intact:

    jar tf myjar.jar

  2. Restart eclipse and update projects setting over right click on project -> Maven -> Update project

  3. The option which has work for me was to navigate in the workspace folder and then delete the files:

    .metadata/.plugins/org.eclipse.jdt.core/invalidArchivesCache .metadata/.plugins/org.eclipse.jdt.core/nonChainingJarsCache

After that restart eclipse and rebuild project.

Upvotes: 1

Yogi
Yogi

Reputation: 1712

For Java web application, web.xml added as jar in the project. In project explorer, try to find web.xml as in jar icon and remove from the project. Error will go away!!

Upvotes: 0

Hem M
Hem M

Reputation: 326

i was facing same problem in Eclipse Mars. I downloaded the jars from [https://oss.jfrog.org/webapp/#/artifacts/browse/tree/General/repo/org/ethereum/ethereumj-core/1.0.0-SNAPSHOT][1] and replaced it in the directory.

I got error while adding ethereum.jar using pom.xml at C:\Users{machineName}.m2\repository\org\ethereum\ethereumj-core\1.0.0-SNAPSHOT\ethereum-core-1.0.0-SNAPSHOT.jar , i added the downloaded jar(ethereum-core-1.0.0-SNAPSHOT.jar) here and the problem was solved.

Upvotes: 1

Colm Bhandal
Colm Bhandal

Reputation: 3831

For us, the problem seemed to be the size of the .jar file. I would recommend doing the following test to see whether this is the case or at least rule it out. First have a look at other jars in your Eclipse project and compare them to the problemetic jar. Is it a lot bigger than the others? If so, try the following workaround. Else, this answer probably won't help you. Before starting, configure Windows to treat .jar files as .zip files with the following command line command:

assoc .jar=CompressedFolder (see https://superuser.com/questions/121540/can-you-configure-windows-to-open-jar-files-like-zip-files-without-a-3rd-party-t)

Optional: A simple Test

Before trying the workaround, here is a test to see if it is indeed the jar file size that's tripping you up.

  1. Create a large .jar full of random .class files that aren't in your problematic jar. You can do this by making a folder full of files, zipping it, and renaming the .zip extension to a .jar. Windows might warn you about changing the extension. Ignore this. Make sure you have enough files in the folder so that it's a bit larger than the problematic jar.
  2. Try to import this artificially created jar. If it fails with the same error, then size is probably the issue.

The Workaround

If it is indeed size that's the problem, which you might have identified by doing the optional simple test above, you can try the following workaround.

  1. Decompress your .jar file. You should be able to do this easily in Windows
  2. Split the folder you get from step 1 into smaller sub-folders. It could be just two folders, or more, depending on how big the original is. You want the folders to be smaller than some of your existing "good" jars so that size won't be an issue. Make sure to keep the package structure intact when you're doing this.
  3. Zip up all the folders you created in step 2, and rename the .zip to .jar.
  4. Import all of the .jars from step 3 individually.

The steps might be a bit unclear, so here's an example. Imagine your jar file was called mylib.jar. You unzip this to a folder called mylib. Inside, let's say there are three sub-folders called package1, package2 and package3. Create 3 folders called mylib1, mylib2 and mylib3, and put in package1, package2 and package3 respectively. Then zip these up and rename extension to .jar. You'll then be importing mylib1.jar, mylib2.jar and mylib3.jar.

Upvotes: 0

ChandrasekarG
ChandrasekarG

Reputation: 1383

In my case, the java installation was not proper. So, I uninstalled Java and reinstalled a new version. Now, it works.

Upvotes: 0

samsamara
samsamara

Reputation: 4750

Could be due to corrupted jar files as well. Better to check that first as that was the reason in my case:

 jar tf myjar.jar

should list the content inside.

Upvotes: 1

Mashrur
Mashrur

Reputation: 535

Looks like everyone has different story to tell! For me, I had to delete the error from eclipse Markers tab, and then cleaned the project again. Before that, I closed and re-opened the project/eclipse several times as suggested by @rachit, which did not work for me.

Upvotes: 6

BVtp
BVtp

Reputation: 2480

A solution that worked for me: go to *.classpath and delete the line : <classpathentry kind="lib" path="the_problematic_class.java"/>

Upvotes: 1

mboeckle
mboeckle

Reputation: 972

In my case restarting Eclipse did not solve the problem. I restarted the computer and did a Project -> Clean in eclipse

Upvotes: 1

Jimit Patel
Jimit Patel

Reputation: 4297

I found no duplicates anywhere and tried restarting eclipse, rebuild project. I was getting error for only one libary. So I just tried to rename the jar file from ksoap2-android-assembly-2.5.8-jar-with-dependencies.jar to ksoap2-2.5.8.jar

So if none of the problems solves from above you can also try this one

Upvotes: 0

enri
enri

Reputation: 631

In my case I tried all the tips suggested but the error remained. I solved changing version with a more recent one and writing that in the pom.xml. After this everything is now ok.

Upvotes: 1

lomec
lomec

Reputation: 1354

In my case, i'd downloaded project from internet, after unzipping project some files had been blocked, just unblock files and try again, then problem was solved.

Upvotes: 1

Sandeep P
Sandeep P

Reputation: 4411

There is other case to display error Archive for required library

Right click on project and open --> project project properties --> java build path --> Android private libs

if there are two jar files with same name then remove one from libs.

jar file may the hidden some times then open you libs folder in window and check if any hidden files are exist Organize --> folders and search options --> view --> check show hidden files and Delete the hidden jar file , The same cass delete if hidden java fies exist in src and packages if any

Upvotes: 10

volatilevar
volatilevar

Reputation: 1676

I've seen the same issue. I removed that jar file, and then rightclick on the project, select maven, and do "update project...". The jar was downloaded again, and the problem was gone.

Upvotes: 22

Related Questions