When you develop a spring java project with maven, sometimes you may encounter errors like below. This is a crazy error because the reason is not very clear. I tried a lot of methods such as rebuild the project, recreate the project, and even delete the .m2 directory to re-download all the maven jar files again, but the error still exists. This article will tell you how to fix this problem after my investigation.
Archive For Required Library: ‘.m2/repository/spring-tx-5.0.10.release.jar’ In Project Cannot Be Read Or Is Not A Valid Zip File
1. Method To Fix Can Not Read Maven Repository Jar File.
- Since the error message said the target jar file is not a valid ZIP file or can not be read, so first you had better go to the target file stored directory and check whether it is a valid file and then unzip it to see whether it can be unzipped or not.
- If the file is a good zip file, then check whether the file exists in the project java build path.
- Expand the spring project Maven Dependencies jar file folder in the project left panel. Then you can look for that jar file there, in this example, the jar file is spring-tx-5.0.10.release.jar.
- You can see that the jar file can not be expanded to show the java classes under it like other jar files. This is just the reason for this error.
- Now right-click the spring-tx-5.0.10.release.jar file, click the Refresh menu item in the popup menu list to list all the java classes under the jar file, then clean and rebuild the project again then the error message will disappear.
- If the error still exists, then unzip the spring-tx-5.0.10.release.jar file to a folder and refresh the jar file again until the java classes under that jar file are shown.
2. Fix Can Not Import Spring Annotation Java Class Error.
- This method is also effective when the spring tool suite can not identify a spring annotation class such as @Autowired etc, you need to right-click the Maven Dependencies folder and click the Refresh button to refresh all the jar files in it.
- Then right-click the red line under the @Autowired annotation, it will popup a menu list and click the import menu item to import @Autowired annotation class.