48

The Issue

I am unable to compile Java code for an imported Eclipse project on IntelliJ build 182.4505.22 on Java 9 and 10. The following error is displayed when compiling the module, or any individual file:

Error:(1, 1) java: cannot access edu.wit.cs.comp2000

zip END header not found

Details

The structure of the project is as follows: IntelliJ project structure

The full compile-time output is as follows: enter image description here

Already Attempted

I have reviewed posts here and here, which do not provide any relevant details. I have attempted compiling on both Java 9 and 10, which makes no difference. I have written a main method into LinkedBag and attempted to run that independent of JUnit, which results in the same error. IntelliJ is not correctly displaying the testing icons in my test class, so I suspect that JUnit (or lack of JUnit) is the cause of the issue, however I am unsure how to proceed. Compiling works for other projects (without JUnit tests) just fine.

Updates

  • The code seems to compile and test as expected on Java 1.8 without issue. Switching to Java 9 or 10 causes the above issue every time. I am beginning to suspect that one of my instructor's dependencies requires Java 1.8 specifically, however I would still like to use newer versions of Java if anyone might have a solution.
J. Blackadar
  • 1,821
  • 1
  • 11
  • 18
  • 1
    It also might be a bug in JDK 9/10 – y.bedrov Sep 20 '18 at 10:48
  • Probably not a bug. They've started removing things from JDKs newer than 8 that you might be depending on. The solution is to add those dependencies back in your Maven pom.xml. – duffymo Nov 04 '19 at 14:57
  • Clearing maven cache by deleting the ~/.m2/repository directory worked for me. Thanks, @Fearnbuster – Khushal Vyas Apr 25 '23 at 03:56

10 Answers10

50

As mentioned above, just delete the corrupted cache and restart Intellij.

Running gradle in the commandline can help knowing what you should delete. For instance:

$ ./gradlew --version
Could not unzip /home/cesarc/.gradle/wrapper/dists/gradle-5.6.2-all/9st6wgf78h16so49nn74lgtbb/gradle-5.6.2-all.zip to /home/cesarc/.gradle/wrapper/dists/gradle-5.6.2-all/9st6wgf78h16so49nn74lgtbb.
Reason: error in opening zip file

and after deleting the folder /home/cesarc/.gradle/wrapper/dists/gradle-5.6.2-all/9st6wgf78h16so49nn74lgtbb the problem was solved:

$ ./gradlew --version
Downloading https://services.gradle.org/distributions/gradle-5.6.2-all.zip
......
Fulvio Flaco
  • 656
  • 5
  • 6
21

We had this issue when internet connection dropped while Idea was downloading project dependencies. We solved it by deleting the corrupted file from cache. Cache location depends on your build tool, e. g. for Maven it's in ~/.mvn, for Gradle it's in ~/.gradle.

dizeee
  • 400
  • 2
  • 7
  • 6
    +1 for this. I was using Maven in my project, not Gradle. To clear the Maven cache, you must delete the `~/.m2/repository` directory – Fearnbuster Sep 30 '22 at 14:28
11

In my case, it was: /.m2/repository/org/apache/tomcat/embed/tomcat-embed-core/9.0.41/tomcat-embed-core-9.0.41.jar I just removed it and I was able to compile my code. Just pay attention to the .jar file in your case it's giving an error. Just remove it and you are good to go.

Abhishek Patre
  • 111
  • 1
  • 2
7

I Had Similar issue in my mac.I just deleted .m2 repository and did maven clean install again worked.

Rocky4Ever
  • 828
  • 3
  • 12
  • 35
5

Instead of deleting your whole maven repository you can scan through it locally to find the bad jar file using GNU utils

find <maven-repository-dir> -type f -name "*.jar" -exec zip -T {} \; grep -v OK
2

I got this error

[ERROR] error reading /Users/username/.m2/repository/io/confluent/common-config/5.5.1/common-config-5.5.1.jar; zip END header not found

I don't know why the jar was corrupted but the error went away when I replaced the jar with my colleagues jar file. Fixing the error temporarily.

Swoot
  • 1,304
  • 11
  • 12
1

In my case, the gradle version of the project was 6.2.2 and the 6.4.1(system default gradle) path was provided in the Intellij gradle settings. This issue appeared suddenly though. I was working on this project for a long time without any issues. I am not quite sure as to what triggered this issue. The gradle default version package was fine as the gradle build was fine from command line. :)

Referred to suggestions from here

Any one of the below solved the issue on my system:

  • Provide the path to project gradle version, in gradle settings. or
  • Change the 'distributionUrl' value in your gradle-wrapper.properties to have 'all' instead of 'bin'. And also make sure you have gradle-wrapper.properties configured in your intellij gradle settings.

distributionUrl=https\://services.gradle.org/distributions/gradle-6.2.2-all.zip

enter image description here

1

This can also occurs when you use a dependency that requires to be of type pom (to transitively add all dependencies, useful for BOMs) but without specifying it.

For example if you have a Spring Boot project and use that starter :

<dependency>
    <groupId>org.zkoss.zkspringboot</groupId>
    <artifactId>zkspringboot-starter</artifactId>
    <version>${zkspringboot.version}</version>
</dependency>

Then mvn clean package will give you the following error :

Error: java: cannot access com.example.myproject

And running the app will result in the following error :

java: error reading ...\.m2\repository\org\zkoss\zkspringboot\zkspringboot-starter\2.3.0\zkspringboot-starter-2.3.0.jar; zip END header not found

because it should not perform any packaging.

Adding the pom packaging type fixes the problem, so that it keeps the artifact simply as a descriptor of dependency versions :

<dependency>
    <groupId>org.zkoss.zkspringboot</groupId>
    <artifactId>zkspringboot-starter</artifactId>
    <version>${zkspringboot.version}</version>
    <type>pom</type>
</dependency>
Yann39
  • 14,285
  • 11
  • 56
  • 84
  • After I struggled a whole day with this issue, this was the solution for my problem! – ersu May 08 '21 at 08:59
0

Tweak file watching settings did the trick for me.

For Ubuntu/Mac Run these 2 commands.

sudo echo "fs.inotify.max_user_watches = 524288" | sudo tee /etc/sysctl.d/40-idea.conf

sudo sysctl -p --system
Supun Wijerathne
  • 11,964
  • 10
  • 61
  • 87
-1

I had a similar issue when I used the dependency thymeleaf-extras-springsecurity4 from org.thymeleaf.extras in a spring boot application.

Updating the dependency to the latest version helped.

malliaridis
  • 389
  • 1
  • 12