简体   繁体   中英

Generate JNI header file in different packages

If I have all my .java and .class files in one place (ie in the default package) then everything is OK and I do all the JNI stuff, etc. But in this case I have package-ception (lots of directories), my class and Java files are separated in /bin and /src and so on. And I need to generate the header file, but I am getting errors all the time. I tried so many commands, I saw different tutorials. I am already out of options. So my project is in c://gvk/SEP3 and then the class and Java files with the native methods that I am gonna use are in /bin/CalculatorServer and /src/CalculatorServer

I have all the time run the javah command from the directory where the class file with the native methods is. The commands I tried so far are:

javah -d ./CalculatorServer NativeMethodsCalculator

Error: Could not find class file for 'NativeMethodsCalculator'.

javah -d ./CalculatorServer CalculatorServer.NativeMethodsCalculator

Error: Could not find class file for 'CalculatorServer.NativeMethodsCalculator'.

javah -d c://gvk/SEP3/bin/CalculatorServer -classpath c://gvk/SEP3/bin/CalculatorServer NativeMethodsCalculator

Error: Could not find class file for 'NativeMethodsCalculator'.

javah -classpath c://gvk/SEP3/bin/CalculatorServer -o NativeMethodsCalc.h src.CalculatorServer.NativeMethodsCalculator

Error: Could not find class file for 'src.CalculatorServer.NativeMethodsCalculator'.

javah -jni bin.CalculatorServer.NativeMethodsCalculator

Error: Could not find class file for 'bin.CalculatorServer.NativeMethodsCalculator'.

I have all the time run the javah command from the directory where the class file with the native methods is

That's your mistake. You should run it from the directory that contains the outermost package, with the inner packages and their .class files below it. Then you don't need a -d argument or a -classpath argument. Assuming your outermost package is CalculatorServer, you should be in the directory containing CalculatorServer, and the command line required is javah CalculatorServer.NativeMethodsCalculator .

What you didn't try: go just to /bin/ ( not into CalculatorServer ) and run

javah -jni CalculatorServer.NativeMethodsCalculator

This is the only way how to run it . Just look at the javah doc . It says " fully-qualified-classname " in the synopsis. " Fully qualified " means full classpath . You were giving it only the classname. It worked for you so far only because you were using a default package, which means that your fully qualified classname was equal to a bare classname.

Option -d and -o doesn't influence the class lookup, only the storage of native result. All the variants you tried do not make any difference to your mistake.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM