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

160,027

Solution 1

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

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

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

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

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'
Share:
160,027

Related videos on Youtube

totalcruise
Author by

totalcruise

Updated on July 05, 2022

Comments

  • totalcruise
    totalcruise about 2 years

    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

    • dma_k
      dma_k over 12 years
      You need to execute install goal for maven: look for context menu for m2e. This will fetch all missed dependencies.
    • totalcruise
      totalcruise over 12 years
      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...
    • dma_k
      dma_k over 12 years
      If jar files are there, try to refresh your project. Usually that helps.
    • totalcruise
      totalcruise over 12 years
      Okay that has helped - other errors now - but this has helped. Thanks
  • pjco
    pjco almost 12 years
    Simply relaunching Eclipse worked for me after adding an existing project to a new Git repo. Thanks +1
  • dfdumaresq
    dfdumaresq over 11 years
    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.
  • Alex
    Alex over 10 years
    Eclipse relaunching does not work for me, deleting/importing does work
  • Paul Richter
    Paul Richter about 10 years
    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.
  • Bala
    Bala about 6 years
    I think its ALT + F5
  • J E Carter II
    J E Carter II almost 6 years
    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.
  • Vaibhav Miniyar
    Vaibhav Miniyar almost 6 years
    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 :)