Bonjour,
je cherche désespérement à réaliser le tuto de sun sur jni:
J'ai crée le fichier source java:http://java.sun.com/docs/books/tutorial/native1.1/stepbystep/step1.html
Je l'ai compilé:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14 package jni; class HelloWorld { public native void displayHelloWorld(); static { System.loadLibrary("hello"); } public static void main(String[] args) { new HelloWorld().displayHelloWorld(); } }
J'ai crée le fichier header:d:\java\jni\java -classpath . HelloWorld.java
J'obtiens ainsi jni_helloworld.h.d:\java\javah -classpath . jni.helloworld
J'ai crée le fichier jni_helloworld.c:
Je l'ai compilé pour obtenir hello.dll
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11 #include <jni.h> #include "jni_HelloWorld.h" #include <stdio.h> JNIEXPORT void JNICALL Java_HelloWorld_displayHelloWorld(JNIEnv *env, jobject obj) { printf("Hello world!\n"); return; }
J'exécute:
et j'obtiens le message :d:\java\java -classpath . jni.helloworld
Merci pour votre aide.java.lang.UnsatisfiedLinkError: no hello in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1517)
at java.lang.Runtime.loadLibrary0(Runtime.java:788)
at java.lang.System.loadLibrary(System.java:834)
at jni.HelloWorld.<clinit>(HelloWorld.java:7)
Exception in thread "main"
Java Result: 1
Parce que ça fait un moment que je cherche et pas moyen de réussir.
Ciao.
Partager