0

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?

Community
  • 1
  • 1
user3668129
  • 4,318
  • 6
  • 45
  • 87

1 Answers1

1
  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.

Jens
  • 67,715
  • 15
  • 98
  • 113
  • Thanks. So if I have project A.jar and project B.jar use A.jar. So project C jar which use B.jar must contain A.jar and B.jar ? Why it is not enough to contain only the B.jar (seem the right logic way... no ?) – user3668129 Feb 07 '15 at 16:34
  • @user3668129 Because A.jar does not contains B.jar. If you use a deependency management like maven it will be manage such dependency. – Jens Feb 07 '15 at 16:38