Question

I'm new to using jar files on my applications so here is my problem. I wrote my code on net beans and added into the library the jar file I need, which is: poi-3.10-FINAL. The program runs perfectly from net-beans, however when i try to run it from the command line seems like it doesn't find some of the files inside the jar. Reason for this I would like to make it an executable after i get this solved.

In the command line I'm compiling my code as follows:

C:\Users\chuser10\Desktop\Excel\src\excel>javac *.java -cp C:\Users\chuser10\Des
ktop\Excel\src\excel\lib\poi-3.10-FINAL.jar

It compiles perfectly, which lead me to think everything is good to go, however this is not so. I tried then running my main as ...>java GUI and i got this:

C:\Users\chuser10\Desktop\Excel\src\excel>java GUI
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/apach
e/poi/poifs/filesystem/POIFSFileSystem

I checked inside the jar and the file is there. Any clue why this might be?

Était-ce utile?

La solution

You need to specify the classpath when you run the program too. Compiling doesn't link the library into your code as happens in C and many other languages; in Java linking happens at runtime.

Probably -cp .;C:\Users\chuser10\Desktop\Excel\src\excel\lib\poi-3.10-FINAL.jar will be what you need. The '.' at the beginning means the current directory, which is where the class files that constitute your program are rooted. The ';' is just a separator.

Autres conseils

Got it working. You are both correct, we have to specify the class-path at runtime as well.

I went ahead and went for the executable jar file creation and put it on my manifest:

..>jar cfm < *.class>

On my manifest:

Class-Path: poi-3.10-FINAL.jar Main-class: GUI

Cheers!

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top