1
votes

I tried to implement JNI.

first I create Java class containing one native method, and compile it using "javac HelloWorld.java" and then create header file using "javah HelloWorld" ... here is the code

class HelloWorld {
     private native void print();
     public static void main(String[] args) {
         new HelloWorld().print();
     }
     static {
         System.loadLibrary("HelloWorld");
     }
 }

HelloWorld.h file is as shown below .....

/* DO NOT EDIT THIS FILE - it is machine generated */
#include 
/* Header for class HelloWorld */

#ifndef _Included_HelloWorld
#define _Included_HelloWorld
#ifdef __cplusplus
extern "C" {
#endif
/*
 * Class:     HelloWorld
 * Method:    print
 * Signature: ()V
 */
JNIEXPORT void JNICALL Java_HelloWorld_print
  (JNIEnv *, jobject);

#ifdef __cplusplus
}
#endif
#endif

after this i created HelloWorld.c file ... here is the code

 #include 
 #include 
 #include "HelloWorld.h"

 JNIEXPORT void JNICALL 
 Java_HelloWorld_print(JNIEnv *env, jobject obj)
 {
     printf("Hello World!\n");
     return;
 }

and then compile my HelloWorld.c file using below mention command in Visual studio 2008

cl -Ic:\java\jdk\include -Ic:\java\jdk\include\win32 -MD -LD HelloWorld.c -FeHelloWorld.dll

it compiles pretty well and dll and other files are created in the same bin folder where "HelloWorld.class" file is . but while running java file using "java HelloWorld" command msvcr90.dll file missing error occurs.... I tried to reinstall my JDK but still same problem

what should I do ...

1

1 Answers

0
votes

This error is related to build settings in Visual Studio. You can select static link of CRT library (use /MT option instead /MD) or copy msvcr90.dll to directory with your HelloWorld.dll or other directory in %PATH%.