Bonjour,

je cherche désespérement à réaliser le tuto de sun sur jni:
http://java.sun.com/docs/books/tutorial/native1.1/stepbystep/step1.html
J'ai crée le fichier source java:
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();
    }
}
Je l'ai compilé:
d:\java\jni\java -classpath . HelloWorld.java
J'ai crée le fichier header:
d:\java\javah -classpath . jni.helloworld
J'obtiens ainsi jni_helloworld.h.
J'ai crée le fichier jni_helloworld.c:
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;
}
Je l'ai compilé pour obtenir hello.dll

J'exécute:
d:\java\java -classpath . jni.helloworld
et j'obtiens le message :

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
Merci pour votre aide.
Parce que ça fait un moment que je cherche et pas moyen de réussir.
Ciao.