0

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)

elmarco
  • 31,633
  • 21
  • 64
  • 68
  • 1
    You need the JDK classpath use builtin classes like `Object` and `String` Are you trying to replace all the built in classes? (You can do this but I don't know what you are trying to achieve) – Peter Lawrey Mar 24 '11 at 13:13
  • Oh I do want the system class, but I want the local "." path to be in the classpath as well. Let me update the question to make it more clear what the problem is. – elmarco Mar 24 '11 at 13:16
  • You shouldn't have to but it appear you need to add ':' to the start of your class path. My guess is that the '//' at the start of your path is confusing it. – Peter Lawrey Mar 24 '11 at 13:25

3 Answers3

1

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)

Andreas Dolk
  • 113,398
  • 19
  • 180
  • 268
1

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.

gustafc
  • 28,465
  • 7
  • 73
  • 99
1

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.

user unknown
  • 35,537
  • 11
  • 75
  • 121
  • you are right! it's been a long time I didn't touch java, and all I need is just a `make dist` to pass. Thanks – elmarco Mar 24 '11 at 14:25