0

I have problem with NoClassDefFoundError. In my project I am using zip4j external library to unzip files. I use: java 16, maven and IntelliJ. When I run my application in IDE everything works. But When I'm trying to run it from .jar file NoClassDefFoundError is poping out. Depencency for zip4j is shown below:

    <!-- https://mvnrepository.com/artifact/net.lingala.zip4j/zip4j -->
    <dependency>
      <groupId>net.lingala.zip4j</groupId>
      <artifactId>zip4j</artifactId>
      <version>2.9.0</version>
    </dependency>

In my main class I use ZipFile object that is imported from zip4j. When I comment this line .jar file is executed properly. Is this the issue where my application/maven cannot take this library to .jar file? I googled it in every possible way. I added dependency in project structure, which was downloaded from maven repository and still nothing. I red somewhere that this needs to be added to classPath - how can I do it? I am now trying to solve this for 5+ hours, will be very greatful if somebody could help me out. Thank you in advance.

1 Answers1

0

The file structure in Jar is different from the file structure of our project in IDE. I have faced this issue many times while working with Jars. For better understanding try to unzip Jar to see the internal file structures. I resolved it by using below line of code :

Thread.currentThread().getContextClassLoader().getResource("filename").getPath();

O_K
  • 922
  • 9
  • 14