hi all, Can anybody suggest any good book for the JNI technology.I have to use it in my project. Thanks, Pradnya
Manjunath Reddy
Ranch Hand
Joined: Jul 26, 2001
Posts: 60
posted
0
Trupti, As far as i have seen and used JNI, it doesnt require a real "Book" to illustrate its concepts, as its pretty easy to follow. Why dont you check out the java.sun.com <http://developer.java.sun.com/developer/onlineTraining/Programming/JDCBook/jni.html> or start from src of sample dlls written for JNI. One can take off from there and write his own dll's and start using/testing them thru java. my .02, Cheers
hi Manjunath, i have a question.i am trying to do the example from the java.sun.com site. I created the .java file (which calls the native method ),i compiled the .java file. Then i created the .h file by using the javah utility. then i wrote the implementation. do we need to include the jni.h file? i am getting the following error when i compile the .c file. "HelloWorldImp.c", line 1: cannot find include file: <jni.h> "./HelloWorld.h", line 2: cannot find include file: <jni.h> "./HelloWorld.h", line 15: undefined or not a type: JNIEXPORT "./HelloWorld.h", line 15: void parameter cannot have name: JNICALL "./HelloWorld.h", line 15: parameter not in identifier list: JNICALL "./HelloWorld.h", line 15: syntax error before or at: Java_HelloWorld_displayHelloWorld "./HelloWorld.h", line 16: syntax error before or at: * Also how to create the shared library? what path exactly we need to set up? thanks, trupti
Manjunath Reddy
Ranch Hand
Joined: Jul 26, 2001
Posts: 60
posted
0
Trupti, For simplicity sake lets assume that you are working in the c:\jni folder. Here are the steps( All files are generated in the same folder) 1.Write the .java file 2.Use Javah utility to generate the .h file 3.Use notepad or vc++ editor to write the implementation, the file includes the jni.h file found in <jdk install folder>/include directory. 4.Compile using the following attributes C:\jni>cl -Ic:\jdk1.3\include -Ic:\jdk1.3\include\win32 -LD TestImp.c -Fetest.dll. Output is something like C:\jni>cl -Ic:\jdk1.3\include -Ic:\jdk1.3\include\win32 -LD TestImp.c -Fetest.dll Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8168 for 80x86 Copyright (C) Microsoft Corp 1984-1998. All rights reserved. TestImp.c Microsoft (R) Incremental Linker Version 6.00.8168 Copyright (C) Microsoft Corp 1992-1998. All rights reserved. /dll /implib:test.lib /out:test.dll TestImp.obj Creating library test.lib and object test.exp 5.You might see that the file test.dll or test.so(linux) is generated in the folder 6.Run your sample Class..and u must see the result.
Hope this cobbled up stuff helps... Lemme know if you have any specific probs. Cheers!
Manjunath Reddy
Ranch Hand
Joined: Jul 26, 2001
Posts: 60
posted
0
Seems the directory url got messed up again...here it goes 3.Use notepad or vc++ editor to write the implementation, the file includes the jni.h file found in c:\jdk1.3\include directory.