0

I'm trying to find more information on how eclipse handles Running a project. I want to understand it more because I have an issue I'm currently having where apache-poi .jar files which have been included into the classpath of my project will work properly when the project is ran through eclipse, but will not be detected when going to the same projects folder and running the main jar file to start the program.

It gives me the error: java.lang.NoClassDefFoundError: org/apache/poi/ss/usermodel/Cell (although sometimes instead of Cell, it's Sheet)

What could I consult to understand what is going on here, and possibly solve this issue?

Zyzyx
  • 492
  • 4
  • 18
  • 1
    What do you mean? Invoking java via the command line? The command line knows nothing about project structure or classpath setup. Unless you set the class path somehow. – GhostCat Jun 01 '18 at 10:28
  • I'm not too sure on the specifics of eclipse, but I'm assuming your Apache poi dependency isn't being included in your output jar. If you are using maven I'd suggest looking into the shade plugin, otherwise eclipse may have a setting for including dependcies in your artifacts – dustinroepsch Jun 01 '18 at 10:29
  • In any case we can't help with such incomplete information. Please read [mcve] and enhance your question accordingly. – GhostCat Jun 01 '18 at 10:34
  • Possible duplicate of [What does "Could not find or load main class" mean?](https://stackoverflow.com/questions/18093928/what-does-could-not-find-or-load-main-class-mean) – vincrichaud Jun 01 '18 at 11:05

1 Answers1

0

Your NoClassDefFoundError indicates that the library was not available while running the jar.

This depends upon how you are exporting your project into the jar file.

If you're using eclipse to do so, you can:

Export->Java->Runnable Jar to create a jar that includes its dependencies

Make sure to check Package required libraries into generated JAR.

This will make all your jars (in build path including apache-poi.jar) as a part of the final jar.

It runs from eclipse because libraries are on the build path of the eclipse which makes them available in the classpath.

Shanu Gupta
  • 3,699
  • 2
  • 19
  • 29