简体   繁体   中英

Why I'm Getting java.lang.NoClassDefFoundError while using jar which use poi jars

I'm using Eclipse in order to compile & run Java applications. I'm creating several projects, which I export as a jar file and import (add to build path) them as jar file in the other projects. I add the jar as follows:

  • copy the jar to the project I want
  • right click on the jar -> build path -> add to build path

It is my first time I'm getting this error:

java.lang.NoClassDefFoundError

I created a project which uses POI jars. The project name is "A". I export this project to A.jar file and import it (add to build path) in B project. When I'm running the B project and try to init (call the constructor) of an object from A.jar, I'm getting the following error:

java.lang.NoClassDefFoundError: org/apache/poi/ss/usermodel/CellStyle

I checked the following threads:

But didn't find the answer.

  1. Why am I getting this error? It isn't my first time, that I'm importing/adding to build path. But now I'm getting an error.

  2. How can I solve it?

  1. You get the error, because the classloader do not find the class.

  2. You have to add the jar that containing the class poi-<version>.jar to the classpath.

The build path only defined the path for the compiler. It not define that the class is in the classpath at runtime.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM