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

24

81

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

Alienist answered 13/1, 2012 at 22:16 Comment(4)
You need to execute install goal for maven: look for context menu for m2e. This will fetch all missed dependencies.Suribachi
Thanks dma_k, I have tried this but to no avail. The jar is in my .m2 repository..i just dont know why it is not being read...Alienist
If jar files are there, try to refresh your project. Usually that helps.Suribachi
Okay that has helped - other errors now - but this has helped. ThanksAlienist
S
95

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.

Stagnant answered 12/4, 2012 at 12:3 Comment(4)
Simply relaunching Eclipse worked for me after adding an existing project to a new Git repo. Thanks +1Planospore
Seems to be a known bug with Helios (not sure if it exists with Juno). bugs.eclipse.org/bugs/show_bug.cgi?id=375249. Just deleting the project (not the contents) and importing the existing project back into the workspace can fix it, when the jar is valid.Sidewinder
Eclipse relaunching does not work for me, deleting/importing does workSpumescent
Manually cleaning the directory seemed to work for me. Simply rm -rf ~/.m2/repository/<path of dependency> (linux/mac) is all that seems to be required.Aile
M
18

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.

Mornay answered 22/4, 2014 at 14:46 Comment(1)
on ubuntu mvn -install says it's not a valid command I just deleted all files in .m2\repository and updated the maven project from IDE (STS) by alt+f5 then check on "Force update of snapshots/releases" and then OK...solved my problem..THANKS :)Dortch
U
9

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.

Unreality answered 6/11, 2014 at 17:32 Comment(0)
J
6

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

Jobyna answered 6/5, 2017 at 10:45 Comment(1)
I think its ALT + F5Wagtail
F
6

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'
Fried answered 25/8, 2018 at 7:42 Comment(0)
C
3

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.

Chide answered 21/11, 2018 at 12:56 Comment(0)
B
2

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.

Barboza answered 30/7, 2015 at 19:20 Comment(1)
I had an issue similar to this where adding application.properties to a source folder caused it to be added as an application library in eclipse Oxygen. It was producing the error Archive for required library: 'src/main/resources/application.properties' in project cannot be read or is not a valid ZIP, and removing that dependency from the build path resolved the issue.Imminent
P
1

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.

Patagonia answered 8/6, 2014 at 11:50 Comment(0)
W
1

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

Watch answered 3/11, 2016 at 14:30 Comment(0)
D
1

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.

Depute answered 15/12, 2018 at 16:42 Comment(0)
E
1

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.

Ephor answered 22/5, 2020 at 10:55 Comment(0)
K
1

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

workspace/.metadata/.plugins/org.eclipse.jdt.core
Kudva answered 29/10, 2020 at 23:27 Comment(0)
C
0

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.

Congratulate answered 25/8, 2016 at 4:49 Comment(0)
L
0

Remove maven dependenices from build path

Lida answered 8/2, 2017 at 3:25 Comment(0)
M
0

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.

Mehalick answered 16/6, 2017 at 11:5 Comment(0)
C
0

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.

Cahilly answered 22/1, 2018 at 13:11 Comment(0)
D
0

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

Drabeck answered 17/2, 2018 at 7:30 Comment(0)
U
0

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.

Unhopedfor answered 23/2, 2018 at 12:53 Comment(0)
F
0

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!

Friseur answered 6/4, 2018 at 23:3 Comment(0)
B
0

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.

Balliol answered 25/10, 2018 at 21:24 Comment(0)
S
0

Alternatively, below commands also worked for me:

mvn -s settings.xml eclipse:clean
mvn -s settings.xml eclipse:eclipse
Serigraph answered 29/8, 2019 at 9:54 Comment(0)
R
0

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

Regulable answered 29/6, 2020 at 11:9 Comment(0)
M
0

In my case, I just had to remove the following 2 lines from proguard.cfg:

-keep class android.support.v4.** { * ; }
-dontwarn android.support.v4.**

Yes, I know that the question refers to the Spring Tool Suite but:

  1. Spring Tool Suite is based on Eclipse (the IDE I am currently using for ADT).
  2. Proguard is a Java obfuscator that can be used for any project, not just Android
  3. I tried all the suggested answers and tips in the thread and none worked for me, until I removed the references to said libs.

I hope this helps someone.

Millais answered 8/12, 2022 at 9:23 Comment(0)
R
-1
Delete your C:\Users\PC\.m2** folder
and update maven project 
Rappee answered 21/11, 2020 at 11:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.