using a library (jcurses) that uses jni

I'm having trouble uses the JCurses library. Here's what's happening:

>ls -A

jcurses.jar .keepme libjcurses.so Test.java

>javac Test.java -classpath jcurses.jar

>ls -A

jcurses.jar .keepme libjcurses.so Test.class Test.java

>java Test -classpath jcurses.jar

Exception in thread"main" java.lang.NoClassDefFoundError: jcurses/system/Toolkit

at Test.main(Test.java:6)

>rm Test.class

>jar xvf jcurses.jar jcurses/

...(no jar error outputs)...

>ls -A

jcurses/ jcurses.jar .keepme libjcurses.so Test.java

>javac Test.java

>ls -A

jcurses/ jcurses.jar .keepme libjcurses.so Test.class Test.java

>java Test

Exception in thread"main" java.lang.ExceptionInInitializerError

at Test.main(Test.java:6)

Caused by: java.lang.NullPointerException

at jcurses.system.Toolkit.getLibraryPath(Toolkit.java:111)

at jcurses.system.Toolkit.<clinit>(Toolkit.java:37)

... 1 more

Why does running "java Test" the first time output something different than the second just because? Also, why isn't the second working?

[1231 byte] By [rosenthaa] at [2007-11-26 12:59:06]
# 1

> Why does running "java Test" the first time output

> something different than the second just because?

Because you are running something different. The first has an explicit class path and the second doesn't.

> Also, why isn't the second working?

Probably because there is something wrong with the test code. Could be the library as well. Could be that you need something on your system that the library needs and which you don't have.

jschella at 2007-7-7 16:57:49 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 2

The reason >java Test

works the second time is because the current directory is apparently on the classpath (even though echo $CLASSPATH

for some reason prints CLASSPATH: Undefined variable.

). I was really asking why >java Test -classpath jcurses.jar

which prints Exception in thread "main" java.lang.NoClassDefFoundError: jcurses/system/Toolkit

at Test.main(Test.java:6)

does not work or even indicate that the jcurses library was found.

rosenthaa at 2007-7-7 16:57:49 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 3

>java Test -classpath

> ... does not

> work or even indicate that the jcurses library was

> found.

Probably because the command syntax is wrong.

The syntax is

java [-options] class [args...]

Anything that follows the class is consider an command line option for the class, not java.

jschella at 2007-7-7 16:57:49 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 4

Ok I got it working now. I used

>java -cp .:jcurses.jar Test

The part that was really confusing me was:

>java -cp jcurses.jar Test

Exception in thread "main" java.lang.NoClassDefFoundError: Test

I forgot that the java command only includes the current directory in the classpath if none is specified. Thats why >java Test

worked: it used the default classpath which consists of the current directory, and the class I was executing and the library I was using were both in the current directory, so java located them, but the library failed because its classes assume that they will be executed from a jar. The reason >java -cp jcurses.jar Test

didn't work is because the current directory was no longer part of the classpath, so java couldn't find the Test class which was in the current directory.

Thanks.

rosenthaa at 2007-7-7 16:57:49 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 5
You might keep in mind that the java class path consists of more than just that option.That option is used in constructing the entire path.The entire path is available during run time as one of the System properties.
jschella at 2007-7-7 16:57:49 > top of Java-index,Java HotSpot Virtual Machine,Specifications...