开发者

Why is CLASSPATH prefixed with JDK path?

开发者 https://www.devze.com 2023-02-19 05:54 出处:网络
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 in

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/jav开发者_Python百科a/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)


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)


I think it's simply a bug in how the javah outputs its actual classpath. What happens is that it has a bunch of places where it searches for built-in classes, and apart from them, it also uses the stuff in $CLASSPATH. When it prints the actual classpath used, they do something like this (pseudo code, assuming implicitEntries is a list of builtin classpath entries, and explicitEntries is a list of the the directories specified in $CLASSPATH):

print implicitEntries.join(pathSeparator) + explicitEntries.join(pathSeparator)

where it should have been

print implicitEntries.join(pathSeparator) + pathSeparator + explicitEntries.join(pathSeparator)

The following works fine for me:

$ ls
Sasl.class  Sasl.java
$ javah -classpath . -o javasasl.h -jni -verbose Sasl     [ Search Path: /usr/java/jdk1.6.0/jre/lib/resources.jar:/usr/java/jdk1.6.0/jre/lib/rt.jar:/usr/java/jdk1.6.0/jre/lib/sunrsasign.jar:/usr/java/jdk1.6.0/jre/lib/jsse.jar:/usr/java/jdk1.6.0/jre/lib/jce.jar:/usr/java/jdk1.6.0/jre/lib/charsets.jar:/usr/java/jdk1.6.0/jre/classes/. ]
[Creating file javasasl.h]
[search path for source files: [.]]
[search path for class files: [/usr/java/jdk1.6.0/jre/lib/resources.jar, /usr/java/jdk1.6.0/jre/lib/rt.jar, /usr/java/jdk1.6.0/jre/lib/sunrsasign.jar, /usr/java/jdk1.6.0/jre/lib/jsse.jar, /usr/java/jdk1.6.0/jre/lib/jce.jar, /usr/java/jdk1.6.0/jre/lib/charsets.jar, /usr/java/jdk1.6.0/jre/classes, /usr/java/jdk1.6.0/jre/lib/ext/dnsns.jar, /usr/java/jdk1.6.0/jre/lib/ext/localedata.jar, /usr/java/jdk1.6.0/jre/lib/ext/sunpkcs11.jar, /usr/java/jdk1.6.0/jre/lib/ext/sunjce_provider.jar, .]]
[loading ./Sasl.class]
[loading /usr/java/jdk1.6.0/lib/ct.sym(META-INF/sym/rt.jar/java/lang/Object.class)]
[loading /usr/java/jdk1.6.0/lib/ct.sym(META-INF/sym/rt.jar/java/lang/Throwable.class)]
[loading /usr/java/jdk1.6.0/lib/ct.sym(META-INF/sym/rt.jar/java/lang/Class.class)]
[done in 585 ms]
$ ls
javasasl.h  Sasl.class  Sasl.java

Now, since the header file generation doesn't seem to work for you... are you sure you have Sasl.class in the current directory? javah works with byte code files, not Java source files.


You show here, that the source file is available ...

(mingw32 *%)$ ls Sasl.java 
Sasl.java

but missing is the class file (Sasl.class).

error: cannot access Sasl
class file for Sasl not found

Compile it first.

0

精彩评论

暂无评论...
验证码 换一张
取 消