29

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?

Aniket Thakur
  • 66,731
  • 38
  • 279
  • 289
  • In my case, the problem was that the library did not have the appropriate permissions, and Eclipse couldn't read it. – crico_aven Jan 20 '16 at 10:30

18 Answers18

49

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.

rachit
  • 1,981
  • 15
  • 23
22

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.

volatilevar
  • 1,626
  • 14
  • 16
10

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

Sandeep P
  • 4,291
  • 2
  • 26
  • 45
  • this was the cause of my problem. The mac I was working on before has created hidden files of each and every file in the project. Thank you. – Mohamed Haseel Mar 25 '14 at 10:52
  • this pointed me in the right direction for a similar problem. Thanks! – Dave Apr 14 '14 at 22:07
6

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.

Mashrur
  • 535
  • 10
  • 22
  • Thank you! This is the only solution that worked for me as well. Also tried cleaning, reopening eclipse and downloading the jar again, but nothing worked. – AlexanderF Aug 16 '17 at 09:05
  • thank you very very much. This is the only solution that worked for me too. Too many time was wasted for me in solving this. Do you have any idea why this happens? – Nasif Imtiaz Ohi Sep 24 '17 at 19:49
  • Same for me. Hmmm got an error message? Just delete it and it will be solved :) LOL – j_kubik Sep 26 '17 at 20:12
  • Thanks! After trying few other options, this one finally worked for me. – emecheon Oct 09 '17 at 15:26
1

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.

lomec
  • 1,356
  • 1
  • 11
  • 10
1

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.

enri
  • 552
  • 1
  • 6
  • 10
1

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

avalancha
  • 1,457
  • 1
  • 22
  • 41
mboeckle
  • 938
  • 13
  • 29
1

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

BVtp
  • 2,308
  • 2
  • 29
  • 68
1

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.

samsamara
  • 4,630
  • 7
  • 36
  • 66
1

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.

Hem M
  • 326
  • 2
  • 13
1

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.

duderoot
  • 977
  • 1
  • 8
  • 23
0

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

Jimit Patel
  • 4,265
  • 2
  • 34
  • 58
0

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

ChandrasekarG
  • 1,384
  • 13
  • 24
0

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.

Community
  • 1
  • 1
Colm Bhandal
  • 3,343
  • 2
  • 18
  • 29
0

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!!

Yogi
  • 1,527
  • 15
  • 21
0

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.

Andy Kofi
  • 9
  • 3
0

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.

Asher
  • 92
  • 1
  • 8
0

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