Bonjour à tous,
je suis entrain de me documenter sur la Java Native Interface pour un futur projet et je me heurte à un problème que je n'arrive pas à résoudre.
Voici ma classe Java [fetchInf.java]:
Je compile le fichier : javac fetchInf.java, j'obtiens fetchInf.class
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8 class fetchInf { private native void fetchInfs(); public static void main(String[] args) { new fetchInf().fetchInfs(); } static { System.load("libfetchInf.so"); } }
Je génère le fichier .h : javah -jni fetchInf, j'obtiens fetchInf.h
J'écris ensuite mon fichier C :
Je build ensuite ma build library libfetchInf.o grace à la commande :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10 #include <jni.h> #include <stdio.h> #include "fetchInf.h" JNIEXPORT void JNICALL Java_fetchInf_fetchInfs(JNIEnv *env, jobject obj) { printf("Hello World!\n"); return; }
cc -shared -g -I/usr/lib/jvm/java-6-sun-1.6.0.15/include -I/usr/lib/jvm/java-6-sun-1.6.0.15/include/linux fetchInf.c -o libfetchInf.so
Jusque là je n'ai aucune erreur !
Dès que je veux exécuter mon fichier Java avec la commande: java fetchInf, j'obtiens l'erreur suivante :
Exception in thread "main" java.lang.UnsatisfiedLinkError: Expecting an absolute path of the library: libfetchInf.so
at java.lang.Runtime.load0(Runtime.java:784)
at java.lang.System.load(System.java:1022)
at fetchInf.<clinit>(fetchInf.java:6)
Could not find the main class: fetchInf. Program will exit.
J'ai cherché sur pas mal de forum mais je n'ai pas trouvé de solution !
Merci d'avance
Partager