add javalibrarypath function
[scilab.git] / scilab / modules / jvm / src / c / addToLibrarypath.c
1 /*-----------------------------------------------------------------------------------*/\r
2 /* INRIA 2007 */\r
3 /* Allan CORNET */\r
4 /*-----------------------------------------------------------------------------------*/ \r
5 #include <jni.h>\r
6 #include "addToLibrarypath.h"\r
7 #include "getScilabJNIEnv.h"\r
8 #include "../../io/includes/directories.h"\r
9 #include "fromjava.h"\r
10 /*-----------------------------------------------------------------------------------*/ \r
11 BOOL addToLibrarypath(char *librarypathstring)\r
12 {\r
13         BOOL bOK=FALSE;\r
14 \r
15         if (librarypathstring)\r
16         {\r
17                 if ( isdir(librarypathstring) )\r
18                 {\r
19                         JNIEnv * currentENV = getScilabJNIEnv();\r
20                         if (currentENV)\r
21                         {\r
22                                 jclass cls=NULL;\r
23                                 if (IsFromJava())\r
24                                 {\r
25                                         /* Boot loader for scilab and javasci */\r
26                                         /* if scilab is called from java (javasci), we need to update standard java.library.path */\r
27                                         /* doesn't require to add -cp SCI/jar/modules/jvm.jar when you use javasci */\r
28                                         cls = (*currentENV)->FindClass(currentENV, "javasci/LibraryPath");\r
29                                 }\r
30                                 else\r
31                                 {\r
32                                         cls = (*currentENV)->FindClass(currentENV, "org/scilab/modules/jvm/LibraryPath");\r
33                                 }\r
34                                 \r
35                                 if (cls)\r
36                                 {\r
37                                         jmethodID mid=NULL;\r
38                                         mid = (*currentENV)->GetStaticMethodID(currentENV, cls, "addPath","(Ljava/lang/String;)V");\r
39                                         if (mid)\r
40                                         {\r
41                                                 jstring jstr;\r
42                                                 jstr = (*currentENV)->NewStringUTF(currentENV,librarypathstring);\r
43                                                 (*currentENV)->CallStaticObjectMethod(currentENV,cls, mid,jstr);\r
44                                                 bOK=TRUE;\r
45                                         }\r
46                                 }\r
47                         }\r
48                 }\r
49         }\r
50         return bOK;\r
51 }\r
52 /*-----------------------------------------------------------------------------------*/ \r