1

I write a Java program that read text from excel.So I import some jar like this: poi-3.10-beta2-20130904.jar, poi-ooxml-3.10-beta2-20130904.jar, etc., I can run the program correctly in eclipse.But when I package this program with maven to the directory(C:\workspace2\change\bin),

Then I run this program in command like this :

C:\workspace2\change\bin>java GenerateVar

it occurs this error:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/poi/ss/usermodel/Cell
    at GenerateVar.execute(GenerateVar.java:59)
    at GenerateVar.main(GenerateVar.java:25)
Caused by: java.lang.ClassNotFoundException: org.apache.poi.ss.usermodel.Cell
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 2 more
Roman C
  • 49,761
  • 33
  • 66
  • 176
chaser
  • 46
  • 1
  • 6

3 Answers3

0

When you run it from eclipse in the console there's a command that could be used to run the project, you could copy/paste it from the console to your command line.

In the command java GenerateVar you didn't set -cp option. With this option the command line will look like

java -cp poi-3.10-beta2-20130904.jar poi-ooxml-3.10-beta2-20130904.jar ... GenerateVar

Assumed the libraries are in the current dir.

How to use maven plugins to add dependency to your project and build jar you can find here.

See also this answer if you want to modify manifest.mf manually.

Community
  • 1
  • 1
Roman C
  • 49,761
  • 33
  • 66
  • 176
0

You need to specify classpath with all other jars/classes you use in your program. E.g. Setting multiple jars in java classpath

Community
  • 1
  • 1
Admit
  • 4,897
  • 4
  • 18
  • 26
0

over, I change the way do what I want to do. I use the fat jar which is the eclipse plugin to package the program

chaser
  • 46
  • 1
  • 6