Search code examples
javajavah

Why is CLASSPATH prefixed with JDK path?


While trying to build a library that uses javah, I ran into a classpath issue. Apparently, the classpath is prefixed with the JDK path: please notice the final search path is wrong. How should I do instead?

elmarco@makai:~/src/sasl/java/CyrusSasl (mingw32 *%)$ CLASSPATH=$PWD javah -o javasasl.h -jni -verbose Sasl 
error: cannot access Sasl
class file for Sasl not found
javadoc: error - Class Sasl not found.
[ Search Path: /usr/java/jdk1.6.0_24/jre/lib/resources.jar:/usr/java/jdk1.6.0_24/jre/lib/rt.jar:/usr/java/jdk1.6.0_24/jre/lib/sunrsasign.jar:/usr/java/jdk1.6.0_24/jre/lib/jsse.jar:/usr/java/jdk1.6.0_24/jre/lib/jce.jar:/usr/java/jdk1.6.0_24/jre/lib/charsets.jar:/usr/java/jdk1.6.0_24/jre/lib/modules/jdk.boot.jar:/usr/java/jdk1.6.0_24/jre/classes//home/elmarco/src/sasl/java/CyrusSasl ]
elmarco@makai:~/src/sasl/java/CyrusSasl (mingw32 *%)$ ls Sasl.java 
Sasl.java

Thanks for your help!

(this is jdk1.6.0_24 on Fedora 14)


Solution

  • I usually avoid the CLASSPATH environment variable. This should work (and maybe without a problem):

    javah -classpath .;<your-path> -o javasasl.h -jni -verbose Sasl
    

    If don't need nothing but the local path, then you don't have to specify a -classpath option, . is the default value.

    Note - you have to compile Sasl.java first. javah expects a class file. (Getting started)