javah error

P

Praetorian

Hi,
I'm trying out a sample JNI program but am unable to get the javah
tool to work. I have 1 source file, HelloWorld.java in C:\Work
\JNIHelloWorld. These are the contents of this file:

//File: Hello.java
class Hello {
public native void sayHello();
static {
System.loadLibrary("hello");
}
public static void main(String[] args) {
Hello h = new Hello();
h.sayHello ();
}
}

This is how I'm invoking javah.exe:

C:\Work\JNIHelloWorld>javah -classpath .;C:\Work\JNIHelloWorld -
verbose HelloWorld
error: cannot access HelloWorld
class file for HelloWorld not found
javadoc: error - Class HelloWorld not found.
[ Search Path: C:\Program Files\Java\jdk1.6.0_13\jre\lib
\resources.jar;C:\Program Files\Java\jdk1.6.0_13\jre\lib\rt.jar;C:
\Program Files\Java\jdk1.6.0_13\jre\lib\sunrsasign.jar;C:\Program Files
\Java\j
dk1.6.0_13\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.6.0_13\jre\lib
\jce.jar;C:\Program Files\Java\jdk1.6.0_13\jre\lib\charsets.jar;C:
\Program Files\Java\jdk1.6.0_13\jre\classes\.;C:\Work\JNIHelloWorld ]
Error: No classes were specified on the command line. Try -help.

I've also tried the call without the '.' preceding the classpath but
it results in the same error, and its always javadoc that throws the
error, not javah. What am I doing wrong?

Thanks in advance for your help,
Ashish.
 
A

Arne Vajhøj

Praetorian said:
Hi,
I'm trying out a sample JNI program but am unable to get the javah
tool to work. I have 1 source file, HelloWorld.java in C:\Work
\JNIHelloWorld. These are the contents of this file:

//File: Hello.java
class Hello {
public native void sayHello();
static {
System.loadLibrary("hello");
}
public static void main(String[] args) {
Hello h = new Hello();
h.sayHello ();
}
}

This is how I'm invoking javah.exe:

C:\Work\JNIHelloWorld>javah -classpath .;C:\Work\JNIHelloWorld -
verbose HelloWorld
error: cannot access HelloWorld
class file for HelloWorld not found
javadoc: error - Class HelloWorld not found.
[ Search Path: C:\Program Files\Java\jdk1.6.0_13\jre\lib
\resources.jar;C:\Program Files\Java\jdk1.6.0_13\jre\lib\rt.jar;C:
\Program Files\Java\jdk1.6.0_13\jre\lib\sunrsasign.jar;C:\Program Files
\Java\j
dk1.6.0_13\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.6.0_13\jre\lib
\jce.jar;C:\Program Files\Java\jdk1.6.0_13\jre\lib\charsets.jar;C:
\Program Files\Java\jdk1.6.0_13\jre\classes\.;C:\Work\JNIHelloWorld ]
Error: No classes were specified on the command line. Try -help.

I've also tried the call without the '.' preceding the classpath but
it results in the same error, and its always javadoc that throws the
error, not javah. What am I doing wrong?

If you have a file Hello.java with a class Hello, then you
first compile it to Hello.class with:

javac Hello.java

and then you generate Hello.h with:

javah -classpath . Hello

(it seems as if you have some confusion about Hello versus
HelloWorld and I am not sure whether you have compiled
first)

Arne
 
P

Praetorian

Praetorian said:
Hi,
I'm trying out a sample JNI program but am unable to get the javah
tool to work. I have 1 source file, HelloWorld.java in C:\Work
\JNIHelloWorld. These are the contents of this file:
//File: Hello.java
class Hello {
  public native void sayHello();
  static {
    System.loadLibrary("hello");
  }
  public static void main(String[] args) {
    Hello h = new Hello();
    h.sayHello ();
  }
}
This is how I'm invoking javah.exe:
C:\Work\JNIHelloWorld>javah -classpath .;C:\Work\JNIHelloWorld -
verbose HelloWorld
error: cannot access HelloWorld
class file for HelloWorld not found
javadoc: error - Class HelloWorld not found.
[ Search Path: C:\Program Files\Java\jdk1.6.0_13\jre\lib
\resources.jar;C:\Program Files\Java\jdk1.6.0_13\jre\lib\rt.jar;C:
\Program Files\Java\jdk1.6.0_13\jre\lib\sunrsasign.jar;C:\Program Files
\Java\j
dk1.6.0_13\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.6.0_13\jre\lib
\jce.jar;C:\Program Files\Java\jdk1.6.0_13\jre\lib\charsets.jar;C:
\Program Files\Java\jdk1.6.0_13\jre\classes\.;C:\Work\JNIHelloWorld ]
Error: No classes were specified on the command line.  Try -help.
I've also tried the call without the '.' preceding the classpath but
it results in the same error, and its always javadoc that throws the
error, not javah. What am I doing wrong?

If you have a file Hello.java with a class Hello, then you
first compile it to Hello.class with:

javac Hello.java

and then you generate Hello.h with:

javah -classpath . Hello

(it seems as if you have some confusion about Hello versus
HelloWorld and I am not sure whether you have compiled
first)

Arne

That was it! And you're right, I did make a mistake with the class
name; it should've been HelloWorld, not Hello.

Thanks for your help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,586
Members
45,084
Latest member
HansGeorgi

Latest Threads

Top