c6163a204b73b3d614727c19179cd2f77bda4fab
[scilab.git] / scilab / modules / jvm / src / c / InitializeJVM.c
1 /*-----------------------------------------------------------------------------------*/
2 /* INRIA 2007 */
3 /* Allan CORNET */
4 /*-----------------------------------------------------------------------------------*/ 
5 #include <stdlib.h>
6 #include <stdio.h>
7 #include <string.h>
8 #include "InitializeJVM.h"
9 #include "loadClasspath.h"
10 #include "setgetSCIpath.h"
11 #include "MALLOC.h"
12 #include "JVM.h"
13 #include "createMainScilabObject.h"
14 /*-----------------------------------------------------------------------------------*/ 
15 BOOL InitializeJVM(void)
16 {
17         BOOL bOK=FALSE;
18         char *SCIPATH=NULL;
19
20         SCIPATH=getSCIpath();
21
22         bOK=startJVM(SCIPATH);
23
24         if (!bOK)
25         {
26 #ifdef _MSC_VER
27                 MessageBox(NULL,"Scilab cannot open JVM library.","Error",MB_ICONEXCLAMATION|MB_OK);
28 #else
29                 printf("\nError : Scilab cannot open JVM library.\n");
30 #endif
31         }
32         else
33
34         {
35                 #define XMLCLASSPATH "%s/etc/classpath.xml"
36                 char *classpathfile = NULL;
37                 classpathfile = (char*)MALLOC(sizeof(char)*(strlen(SCIPATH)+strlen(XMLCLASSPATH)+1));
38                 sprintf(classpathfile,XMLCLASSPATH,SCIPATH);
39                 LoadClasspath(classpathfile);
40                 if (classpathfile) {FREE(classpathfile); classpathfile = NULL;}
41
42                 bOK = createMainScilabObject();
43
44                 if (!bOK)
45                 {
46 #ifdef _MSC_VER
47                         MessageBox(NULL,"Scilab cannot create Scilab Java Main-Class. (we have not been able to find the main Scilab class. Check if the Scilab and thirdparty packages are available).","Error",MB_ICONEXCLAMATION|MB_OK);
48 #else
49                         printf("\nError : Scilab cannot create Scilab Java Main-Class. (we have not been able to find the main Scilab class. Check if the Scilab and thirdparty packages are available).\n");
50 #endif
51                 }
52         }
53
54         if (SCIPATH) {FREE(SCIPATH);SCIPATH=NULL;}
55
56         if (!bOK) exit(1);
57
58         return bOK;
59 }
60 /*-----------------------------------------------------------------------------------*/ 
61