Compiler error "archive for required library could not be read" - Spring Tool Suite

JavaMavenM2eclipseSts SpringsourcetoolsuiteM2e

Java Problem Overview


I am starting to configure my development environment and I am using Spring Tool Suite 2.8.1 along with m2E 1.01.

As far as I can tell, since this is a Maven Project (my first), my Maven POM is dictating (along with m2E smarts) my project build configuration and dependencies.

What I would like to know is why my IDE is displaying Java Build Problems that read "Archive required for library library/path/somejar.jar cannot be read or is not a valid zip file" when I can see the jars in my .m2 repository?

All the errors pertained to commons-logging:1.1.1 which I excluded in my parent-pom. This was a transistive dependancy via spring-context-support:3.0.5. I excluded that library from my build and now the errors pertain to the spring-context-support library.

I have attached a screenshot to illustrate.

Markers

Java Solutions


Solution 1 - Java

Indeed IDEs often cache the local repository (Eclipse does something similar, and I have to relaunch Eclipse).

One ugly maven behavior you might encounter is that if you declare a dependency before you actually install it, maven will create an empty version of the missing dependency (folder with metadata but no jar), and you will have to manually clean your .m2 repository.

Third, an installed archive (jar...) can get corrupted, so try to open it with any archive tool (7zip...) to test it, and delete the whole folder if the archive is corrupted.

Solution 2 - Java

In my case I had to manually delete all the files in .m2\repository folder and then open command prompt and run mvn -install command in my project directory.

Solution 3 - Java

I was using Eclipse as IDE and I was getting very same error. I had to do Project->Maven->Update Project. Select all the checkboxes below except "offline" esp. the one "Force update of snapshots/releases" and click OK. Did the Clean Build for the Project again.

Solution 4 - Java

Delete corrupted files from your local .m2 repository and Ctrl+F5 (Update Maven Project) in Eclipse/STS. It'll download and install these files.

Solution 5 - Java

This worked for me.

  1. Close Eclipse
  2. Delete ./m2/repository
  3. Open Eclipse, it will automatically download all the jars
  4. If still problem remains, then right click project > Maven > Update Project... > Check 'Force Update of Snapshots/Releases'

Solution 6 - Java

For Googlers:

In my case I had accidentally manually added a Java class to the build path while poking around Eclipse. By taking a look at the 'Configure Build Path...> Libraries I removed the culprit class and now only have the

  • JRE System Library
  • Maven Dependencies

and nothing is complaining.

Solution 7 - Java

Below Steps resolved my issue.

  1. Go to ./m2/repository folder.

  2. Go to respective archive error folder.

  3. Verify any zip file is exist.

  4. delete error name folder.

  5. Now come to Eclipse Project - Right Click - Maven - > Update Project.

Above trick works for me.

Solution 8 - Java

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

Solution 9 - Java

I deleted the local maven repository. Then just rightclick the project -> Maven -> Update Project... Select all concerned projects and click OK.

Solution 10 - Java

I was facing the same problem with my project.

My project was not able to find this archive: -

C:\Users\rakeshnarang\.m2\repository\org\hibernate\hibernate-core\5.3.7.Final

I went to this directory and deleted this folder.

Went back to eclipse and hit ALT + F5 to update the project.

The jar file was downloaded again and the problem was solved.

You should try this.

Solution 11 - Java

This happens when Eclipse screws up. To fix it, delete all the files in:

workspace/.metadata/.plugins/org.eclipse.jdt.core

Solution 12 - Java

This could be due to you have added spring-licence.txt file to your web app libraries.

I had similar issue and resolved after removing that text file. In libraries it will expect jar file only.

Solution 13 - Java

Remove maven dependenices from build path

Solution 14 - Java

I faced this problem. I had "Archive for required library spring-boot-devtools cannot be read or is not a valid ZIP file" and the solution was like that:- 1- determine the dependencies names that have problems(for may case it is spring-boot-devtools). 2- close eclipse. 3- search in your .m2 file on these dependencies(by name). 4- delete these folders. 5- reopen eclipse and let maven rebuild your dependencies again.

Solution 15 - Java

Ok, I had the same problem with STS on a mac and solved it by deleting all the files in repository folder and from the STS IDE click on the project and then Maven -> Update project. Give it a couple of minutes to download all the dependencies and the problem is solved.

Solution 16 - Java

I face with the same issue. I deleted the local repository and relaunched the ID. It worked fine .

Solution 17 - Java

Just had this problem on Indigo SR2. It popped up after I removed a superfluous jar from the classpath (build path). Restarting Eclipse didn't help. Added back the jar to the build path...error went away. Removed the jar once again, and this time I was spared from another complaint.

Solution 18 - Java

none of the solutions above helped my problem. I've resolved it by deleting all files in {projectworkspace}/.metadata folder AND in {location}/.m2 folder and let eclipse download every single thing again. Hope this helps someone, cheers!

Solution 19 - Java

When I got an error saying "archive for required library could not be read," I solved it by removing the JARS in question from the Build Path of the project, and then using "Add External Jars" to add them back in again (navigating to the same folder that they were in). Using the "Add Jars" button wouldn't work, and the error would still be there. But using "Add External Jars" worked.

Solution 20 - Java

Alternatively, below commands also worked for me:

mvn -s settings.xml eclipse:clean
mvn -s settings.xml eclipse:eclipse

Solution 21 - Java

In case of VSCode, follow the below steps:

  1. Navigate to the respective folder that contains the corrupted jar
  2. Delete just the jar
  3. mvn clean
  4. mvn compile

That worked for me.

Solution 22 - Java

Read the issue in Problems section,identify which dependency not able to read, then go the maven repository .m2\repository -> 1)check the dependencies and delete it from the folder 2)go to STS/Eclipse -> click on maven -> update project ->select the force update of snapshots/releases and click on ok.

or delete the dependencies from the .m2/repository and rebuild the maven --> update the maven project

Solution 23 - Java

Delete your C:\Users\PC\.m2** folder
and update maven project 

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiontotalcruiseView Question on Stackoverflow
Solution 1 - JavaSamuel EUSTACHIView Answer on Stackoverflow
Solution 2 - JavaintersumView Answer on Stackoverflow
Solution 3 - JavaGopal BairwaView Answer on Stackoverflow
Solution 4 - JavakolobokView Answer on Stackoverflow
Solution 5 - JavaKaushal DokaniaView Answer on Stackoverflow
Solution 6 - JavaHoppyKamperView Answer on Stackoverflow
Solution 7 - JavaRajesh OmView Answer on Stackoverflow
Solution 8 - JavaenriView Answer on Stackoverflow
Solution 9 - JavaPrestigeDevView Answer on Stackoverflow
Solution 10 - JavaRakesh NarangView Answer on Stackoverflow
Solution 11 - JavaNateSView Answer on Stackoverflow
Solution 12 - JavaCHANNA MALLAIAH UDDANDAIAHGARIView Answer on Stackoverflow
Solution 13 - Javabasavaraj NView Answer on Stackoverflow
Solution 14 - JavaAbdollah SobhyView Answer on Stackoverflow
Solution 15 - JavaAlketCecajView Answer on Stackoverflow
Solution 16 - JavareactdontactView Answer on Stackoverflow
Solution 17 - Javaelder elderView Answer on Stackoverflow
Solution 18 - Javavibetribe93View Answer on Stackoverflow
Solution 19 - JavaSteve StilsonView Answer on Stackoverflow
Solution 20 - JavaSnehal MasneView Answer on Stackoverflow
Solution 21 - JavaNaveenView Answer on Stackoverflow
Solution 22 - JavasravaniJView Answer on Stackoverflow
Solution 23 - JavaAvinash KhadsanView Answer on Stackoverflow