0

i am triyng to generate header file for native use (c/c++) from a java file using eclipse. from the command line i can only reach the javah when i am in this location :

C:\Program Files (x86)\Java\jdk1.7.0_51\bin>

but i cant reference my java class like so :

C:\Program Files (x86)\Java\jdk1.7.0_51\bin>javah -jni com.or.jnihelloworld.nativeclass

because the class located outside of this folder at :

C:\Users\Or Azran\workspace\JniHelloWorld\src\NativeLib.java

and i want to make this file in to a jni folder in :

C:\Users\Or Azran\workspace\JniHelloWorld\jni

how can i do it from command line? a good toturial will be also great

honk
  • 9,137
  • 11
  • 75
  • 83
orthehelper
  • 4,009
  • 10
  • 40
  • 67

2 Answers2

3

There appears to be a couple of issues to solve here.

First. I'm not sure that your source code is set up correctly. If indeed your class is com.or.jnihelloworld.nativeclass then it should be in directory: C:\Users\Or Azran\workspace\JniHelloWorld\src\com\or\jnihelloworld\nativeclass.java

However, assuming that the class/directory is correct. The javah command uses -d to specify the output directory, and you can specify the path with -classpath so

javah -classpath "C:\Users\Or Azran\workspace\JniHelloWorld\src\" \ 
-d "C:\Users\Or Azran\workspace\JniHelloWorld\jni" com.or.jnihelloworld.nativeclass

should put the file where you want it.

AllenKll
  • 1,006
  • 2
  • 12
  • 23
  • it dosent work with your example like this : javah -classpath "c:\Users\Or Azran\ workspace\JniHelloWorld\src\" \ -d "c:\Users\Or Azran\workspace\JniHelloWorld\jn i" com.or.jnihelloworld.jnilib.java – orthehelper Mar 21 '14 at 13:29
  • Well the extra slash before the -d indicated it shoudl be one line I broke it into two for readability. – AllenKll Mar 21 '14 at 16:02
  • when i am calling this : javah -classpath "C:\Users\Or\workspace\NativeCodeTest\src\com\infinityar\nativecodetest\" -d "C:\Users\Or\workspace\NativeCodeTest\jni" com.infinityar.nativecodetest.NativeLib i get "ERROR: no classes specified" – orthehelper Mar 23 '14 at 09:12
  • You have compiled your java file first? – AllenKll Mar 24 '14 at 13:47
  • it makes automatic build so i think i do – orthehelper Mar 24 '14 at 16:03
  • In which case the class path will need to find the .class file. – AllenKll Mar 24 '14 at 16:16
1

Your PATH doesn't include the bin directory of the JDK.

user207421
  • 305,947
  • 44
  • 307
  • 483