0

在尝试构建使用 javah 的库时,我遇到了类路径问题。显然,classpath 以 JDK 路径为前缀:请注意最终搜索路径是错误的。我应该怎么做呢?

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

谢谢你的帮助!

(这是 Fedora 14 上的 jdk1.6.0_24)

4

3 回答 3

1

我通常避免使用CLASSPATH环境变量。这应该有效(并且可能没有问题):

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

如果只需要本地路径,则无需指定-classpath选项,.是默认值。

注意- 你必须先编译 Sasl.javajavah需要一个类文件。(入门)

于 2011-03-24T13:23:37.077 回答
1

我认为这只是javah输出其实际类路径的一个错误。发生的情况是它有很多地方可以搜索内置类,除了它们之外,它还使用$CLASSPATH. 当它打印实际使用的类路径时,它们会执行以下操作(伪代码,假设implicitEntries是内置类路径条目的列表,并且explicitEntries是 中指定的目录的列表$CLASSPATH):

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

它应该在哪里

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

以下对我来说很好:

$ 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

现在,由于头文件生成似乎对你不起作用......你确定你Sasl.class在当前目录中吗?javah适用于字节码文件,而不是 Java 源文件。

于 2011-03-24T13:30:51.343 回答
1

您在此处显示源文件可用...

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

但缺少的是类文件(Sasl.class)。

error: cannot access Sasl
class file for Sasl not found

先编译它。

于 2011-03-24T13:40:13.667 回答