JNI

From Informatics

Jump to: navigation, search

see also - CDT for information on configuring the C/C++ development environment in eclipse.

C Configuration

  • Get the Borland C 5.5 compilier from here: http://www.borland.com/downloads/download_cbuilder.html
  • Install in c:\Borland\Bcc55 (the default).
  • In c:\AUTOEXEC.BAT, add the following: SET PATH=%PATH%;c:\Borland\Bcc55
  • In c:\Borland\Bcc55\Bin, create the file bcc32.cfg. Add the lines:
-I"c:\Borland\Bcc55\Include;c:\java\jdk1.5.0_06\include;C:\java\jdk1.5.0_06\include\win32"
-L"c:\Borland\Bcc55\Lib;c:\Borland\BCC55\Lib\PSDK"
  • In c:\Borland\Bcc55\Bin, create the file ilink32.cfg. Add the line:
-L"c:\Borland\Bcc55\Lib"
  • Generate your .h from .java using javah. Before you can do this make sure you have specified which methods you would like to make native (see java configuration below). Then, cd to where your src directory containing the java file and type:

javah -classpath c:\java\apps\eclipse_workspace\workbook\test-classes your.fully.qualified.classname

Make sure the generated .h file is in the src directory. Note that the methods in the .h file will contain argument types, but not variables. You will need to add these variables when you implement the methods in your .c file. For instance, if you end up with (in your .h file):

JNIEXPORT jstring JNICALL Java_wb_test_jni_testJNI_getLine
 (JNIEnv *, jobject, jstring);

You would add the following to your .c file:

JNIEXPORT jstring JNICALL Java_wb_test_jni_testJNI_getLine
 (JNIEnv * env, jobject obj, jstring str);
{
 printf(%s, str);
}
  • From the command line, cd to the directory with your .c file and run: bcc32 -tWM -tWD sourceFile.c.
  • This will generate your .dll file. This dll file is called by your java application.

Java Configuration

  • Declare your native methods:

public native int[][] computeCompleteLinkage(int elements, double matrix[][]);

  • We need to call the .dll file. This is done by:
static {// FIXME do no hardcode this
System.load("C:\\java\\apps\\eclipse_workspace\\workbook\\src\\wb\\plugins\\jni\\analysis\\cluster.DLL");
}

Native C Code Implementation

Personal tools