add javaclasspath(...) primitive
Allan Cornet [Sun, 6 May 2007 15:56:07 +0000 (15:56 +0000)]
Set dynamic Java class path

used in graphics

update javasci ant file
update graphics ant file

18 files changed:
scilab/modules/graphics/etc/graphics.start
scilab/modules/graphics/sci_gateway/c/gw_graphics.c
scilab/modules/graphics/src/java/build.xml
scilab/modules/javasci/src/java/build.xml
scilab/modules/jvm/LibScilab_Import.def
scilab/modules/jvm/Makefile.am
scilab/modules/jvm/includes/addToClasspath.h [new file with mode: 0644]
scilab/modules/jvm/includes/gw_jvm.h
scilab/modules/jvm/jvm.iss
scilab/modules/jvm/libjvm.vcproj
scilab/modules/jvm/sci_gateway/c/gw_jvm.c
scilab/modules/jvm/sci_gateway/c/sci_javaclasspath.c [new file with mode: 0644]
scilab/modules/jvm/sci_gateway/jvm_gateway.xml
scilab/modules/jvm/src/c/JVM.c
scilab/modules/jvm/src/c/JVM_commons.h
scilab/modules/jvm/src/c/addToClasspath.c [new file with mode: 0644]
scilab/modules/jvm/src/java/build.xml [new file with mode: 0644]
scilab/modules/jvm/src/java/org/scilab/modules/jvm/ClassPath.java [new file with mode: 0644]

index 3aa32e7..53a21bd 100644 (file)
@@ -2,6 +2,11 @@
 // graphics module initialisation file 
 // Copyright INRIA 2006
 // ====================================================================
+if (getscilabmode() <> 'NWNI') then
+
+// Load graphics classes
+javaclasspath(SCI+'/java/jar/modules/graphics.jar')
+// ====================================================================
 //Load  functions librarie
 load('SCI/modules/graphics/macros/lib');
 // ====================================================================
@@ -18,4 +23,6 @@ add_module_help_chapter('graphics');
 add_demo("Graphics",pathdemos);
 
 clear pathdemos ;
+
+end // if (getscilabmode <> 'NWNI') then
 // ====================================================================
index 633502b..604ad0e 100644 (file)
@@ -100,8 +100,8 @@ static MatdesTable Tab[]={
        {sci_get,"get"},
        {sci_set,"set"},
        {sci_newaxes,"newaxes"},
-        {sci_relocate_handle,"relocate_handle"},
-        {sci_swap_handles,"swap_handles"},
+    {sci_relocate_handle,"relocate_handle"},
+    {sci_swap_handles,"swap_handles"},
      /* NG end */
        {sci_xsort,"gsort"},
        {sci_help_gtk,"help_gtk"},
@@ -141,7 +141,7 @@ int C2F(gw_graphics)(void)
   }
   else
   {
-         Scierror(999,"graphic interface disabled -nogui mode.\r\n");
+         Scierror(999,"graphic interface disabled -nogui or -nwni mode.\r\n");
          return 0;
   }
 
index cf3f2a9..6277e2e 100644 (file)
@@ -11,13 +11,18 @@ INRIA 2007
    <description>
         build graphics Scilab - Scilab graphics Library
     </description>
+    
+    <target name="init">
+                       <!-- Create the time stamp -->
+                       <tstamp/>
+               </target>    
 
     <target name="clean" description="clean sources">
         <delete dir="build"/>
         <delete file="${dist}/graphics.jar"/>
     </target>
 
-    <target name="compile" description="build sources">
+    <target name="compile" description="build sources" depends="init">
     
         <mkdir dir="build/classes"/>
         <javac srcdir="org" destdir="build/classes"/>
index 1031dfd..1ae97fc 100644 (file)
@@ -5,41 +5,43 @@ INRIA 2007
 -->\r
 <project name="javasci" default="compile">\r
 \r
-<!--\r
- TO DO : add a test on system linux / windows\r
--->\r
-   <property name="dist"  location="../../../../bin" />\r
+   <property name="dist"  location="../../../../java/jar/modules" />\r
    \r
    <description>\r
         build javasci Scilab - Java Interface\r
     </description>\r
+    \r
+    <target name="init">\r
+                       <!-- Create the time stamp -->\r
+                       <tstamp/>\r
+               </target>\r
 \r
     <target name="clean" description="clean sources">\r
         <delete dir="build"/>\r
         <delete file="${dist}/javasci.jar"/>\r
     </target>\r
 \r
-    <target name="compile" description="build sources">\r
+    <target name="compile" description="build sources" depends="init">\r
     \r
         <mkdir dir="build/classes"/>\r
         <javac srcdir="javasci" destdir="build/classes"/>\r
     </target>\r
 \r
-    <target name="jar" description="do .jar file">\r
+    <target name="jar" description="do .jar file" depends="compile">\r
         <jar destfile="${dist}/javasci.jar" basedir="build/classes">\r
             <manifest>\r
-                <attribute name="SciAbstractDataType" value="javasci.SciAbstractDataType"/>\r
-                <attribute name="SciBooleanArray" value="javasci.SciBooleanArray"/>\r
-                <attribute name="SciComplexArray" value="javasci.SciComplexArray"/>\r
-                <attribute name="SciDoubleArray" value="javasci.SciDoubleArray"/>\r
-                <attribute name="SciString" value="javasci.SciString"/>\r
-                <attribute name="BadDataArgumentException" value="javasci.BadDataArgumentException"/>\r
-                <attribute name="SciAbstractArray" value="javasci.SciAbstractArray"/>\r
-                <attribute name="SciBoolean" value="javasci.SciBoolean"/>\r
-                <attribute name="SciComplex" value="javasci.SciComplex"/>\r
-                <attribute name="SciDouble" value="javasci.SciDouble"/>\r
-                <attribute name="Scilab" value="javasci.Scilab"/>\r
-                <attribute name="SciStringArray" value="javasci.SciStringArray"/>\r
+                <attribute name="SciAbstractDataType" value="SciAbstractDataType"/>\r
+                <attribute name="SciBooleanArray" value="SciBooleanArray"/>\r
+                <attribute name="SciComplexArray" value="SciComplexArray"/>\r
+                <attribute name="SciDoubleArray" value="SciDoubleArray"/>\r
+                <attribute name="SciString" value="SciString"/>\r
+                <attribute name="BadDataArgumentException" value="BadDataArgumentException"/>\r
+                <attribute name="SciAbstractArray" value="SciAbstractArray"/>\r
+                <attribute name="SciBoolean" value="SciBoolean"/>\r
+                <attribute name="SciComplex" value="SciComplex"/>\r
+                <attribute name="SciDouble" value="SciDouble"/>\r
+                <attribute name="Scilab" value="Scilab"/>\r
+                <attribute name="SciStringArray" value="SciStringArray"/>\r
             </manifest>\r
         </jar>\r
     </target>\r
index 459b1c8..0dd2c32 100644 (file)
@@ -9,3 +9,11 @@ intersci_
 com_\r
 sciprint\r
 ExceptionMessage\r
+stack_\r
+getrhsvar_\r
+vstk_\r
+checklhs_\r
+checkrhs_\r
+gettype_\r
+getScilabMode\r
+Scierror
\ No newline at end of file
index 6f3c236..5b035b7 100644 (file)
@@ -7,11 +7,13 @@ JVM_C_SOURCES = src/c/InitializeJVM.c \
 src/c/TerminateJVM.c \
 src/c/JVM_Unix.c \
 src/c/JVM.c \
-src/c/JniUtils.c
+src/c/JniUtils.c \
+src/c/addToClasspath.c
 
 GATEWAY_C_SOURCES = sci_gateway/c/gw_jvm.c \
 sci_gateway/c/sci_jvm_version.c \
-sci_gateway/c/sci_with_embedded_jre.c
+sci_gateway/c/sci_with_embedded_jre.c \
+sci_gateway/c/sci_javaclasspath
 
 
 libscijvm_la_CFLAGS=  $(JAVA_JNI_INCLUDE) -I$(top_srcdir)/libs/MALLOC/includes/ -Iincludes/
@@ -44,6 +46,7 @@ includes/getScilabJavaVM.h \
 includes/getScilabJNIEnv.h \
 includes/InitializeJVM.h \
 includes/gw_jvm.h \
-includes/JniUtils.h
+includes/JniUtils.h \
+includes/addToClasspath.h
 
 include $(top_srcdir)/Makefile.incl.am
diff --git a/scilab/modules/jvm/includes/addToClasspath.h b/scilab/modules/jvm/includes/addToClasspath.h
new file mode 100644 (file)
index 0000000..263786b
--- /dev/null
@@ -0,0 +1,18 @@
+/*-----------------------------------------------------------------------------------*/\r
+/* INRIA 2007 */\r
+/* Allan CORNET */\r
+/*-----------------------------------------------------------------------------------*/ \r
+#ifndef __ADDTOCLASSPATH_H__\r
+#define __ADDTOCLASSPATH_H__\r
+\r
+#include "machine.h" /* BOOL */\r
+\r
+/**\r
+* add a path to CLASSPATH\r
+* @param a new path to add\r
+* @return TRUE or FALSE\r
+*/\r
+BOOL addToClasspath(char *classpathstring);\r
+\r
+#endif /* __ADDTOCLASSPATH_H__ */\r
+/*-----------------------------------------------------------------------------------*/ \r
index 335770a..76061f5 100644 (file)
@@ -14,6 +14,7 @@ int C2F(gw_jvm)(void);
 /* used in sci_gateway */\r
 int C2F(sci_with_embedded_jre) _PARAMS((char *fname,unsigned long fname_len));\r
 int C2F(sci_jvm_version) _PARAMS((char *fname,unsigned long fname_len));\r
+int C2F(sci_javaclasspath) _PARAMS((char *fname,unsigned long fname_len));\r
 /*-----------------------------------------------------------------------------------*/\r
 #endif /*  __GW_JVM_H__ */\r
 \r
index df13e3b..b8d3b3f 100644 (file)
@@ -12,6 +12,8 @@
 ;
 Source: bin\libjvm.dll; DestDir: {app}\bin; Components: {#COMPN_SCILAB}
 ;
+Source: java\jar\modules\jvm.jar;DestDir: {app}\java\jar\modules; Components: {#COMPN_SCILAB}
+;
 Source: modules\{#JVM}\licence.txt; DestDir: {app}\modules\{#JVM}; Components: {#COMPN_SCILAB}
 Source: modules\{#JVM}\readme.txt; DestDir: {app}\modules\{#JVM}; Components: {#COMPN_SCILAB}
 Source: modules\{#JVM}\VERSION.xml; DestDir: {app}\modules\{#JVM}; Components: {#COMPN_SCILAB}
index 4c13517..7406f1d 100644 (file)
@@ -59,7 +59,7 @@
                        <Tool\r
                                Name="VCPreLinkEventTool"\r
                                Description="Make dependencies"\r
-                               CommandLine="if NOT EXIST LibScilab.lib lib /DEF:&quot;$(InputDir)LibScilab_Import.def&quot; /SUBSYSTEM:WINDOWS /MACHINE:X86 /OUT:&quot;$(InputDir)LibScilab.lib&quot; 1&gt;NUL 2&gt;NUL&#x0D;&#x0A;cd $(IntDir) &gt;nul&#x0D;&#x0A;for %%f in (*.obj) do  ..\..\..\bin\dumpexts -o %%~nf.def -n libjvm.dll %%f &gt;nul&#x0D;&#x0A;copy *.def libjvmtmp.def &gt;nul&#x0D;&#x0A;copy ..\jvm_header.def+libjvmtmp.def  ..\libjvm.def &gt;nul&#x0D;&#x0A;del *.def &gt;nul&#x0D;&#x0A;cd .. &gt;nul&#x0D;&#x0A;"\r
+                               CommandLine="lib /DEF:&quot;$(InputDir)LibScilab_Import.def&quot; /SUBSYSTEM:WINDOWS /MACHINE:X86 /OUT:&quot;$(InputDir)LibScilab.lib&quot; 1&gt;NUL 2&gt;NUL&#x0D;&#x0A;cd $(IntDir) &gt;nul&#x0D;&#x0A;for %%f in (*.obj) do  ..\..\..\bin\dumpexts -o %%~nf.def -n libjvm.dll %%f &gt;nul&#x0D;&#x0A;copy *.def libjvmtmp.def &gt;nul&#x0D;&#x0A;copy ..\jvm_header.def+libjvmtmp.def  ..\libjvm.def &gt;nul&#x0D;&#x0A;del *.def &gt;nul&#x0D;&#x0A;cd .. &gt;nul&#x0D;&#x0A;"\r
                        />\r
                        <Tool\r
                                Name="VCLinkerTool"\r
@@ -95,6 +95,7 @@
                        />\r
                        <Tool\r
                                Name="VCPostBuildEventTool"\r
+                               CommandLine="set JAVA_HOME=&quot;$(SolutionDir)\java\jdk&quot;&#x0D;&#x0A;set PATH=&quot;$(SolutionDir)\java\ant\bin&quot;;%PATH%;&#x0D;&#x0A;cd src\java&#x0D;&#x0A;ant jar&#x0D;&#x0A;cd  ..\..&#x0D;&#x0A;"\r
                        />\r
                </Configuration>\r
                <Configuration\r
                        <Tool\r
                                Name="VCPreLinkEventTool"\r
                                Description="Make dependencies"\r
-                               CommandLine="if NOT EXIST LibScilab.lib lib /DEF:&quot;$(InputDir)LibScilab_Import.def&quot; /SUBSYSTEM:WINDOWS /MACHINE:X86 /OUT:&quot;$(InputDir)LibScilab.lib&quot; 1&gt;NUL 2&gt;NUL&#x0D;&#x0A;cd $(IntDir) &gt;nul&#x0D;&#x0A;for %%f in (*.obj) do  ..\..\..\bin\dumpexts -o %%~nf.def -n libjvm.dll %%f &gt;nul&#x0D;&#x0A;copy *.def libjvmtmp.def &gt;nul&#x0D;&#x0A;copy ..\jvm_header.def+libjvmtmp.def  ..\libjvm.def &gt;nul&#x0D;&#x0A;del *.def &gt;nul&#x0D;&#x0A;cd .. &gt;nul&#x0D;&#x0A;"\r
+                               CommandLine="lib /DEF:&quot;$(InputDir)LibScilab_Import.def&quot; /SUBSYSTEM:WINDOWS /MACHINE:X86 /OUT:&quot;$(InputDir)LibScilab.lib&quot; 1&gt;NUL 2&gt;NUL&#x0D;&#x0A;cd $(IntDir) &gt;nul&#x0D;&#x0A;for %%f in (*.obj) do  ..\..\..\bin\dumpexts -o %%~nf.def -n libjvm.dll %%f &gt;nul&#x0D;&#x0A;copy *.def libjvmtmp.def &gt;nul&#x0D;&#x0A;copy ..\jvm_header.def+libjvmtmp.def  ..\libjvm.def &gt;nul&#x0D;&#x0A;del *.def &gt;nul&#x0D;&#x0A;cd .. &gt;nul&#x0D;&#x0A;"\r
                        />\r
                        <Tool\r
                                Name="VCLinkerTool"\r
                        />\r
                        <Tool\r
                                Name="VCPostBuildEventTool"\r
+                               CommandLine="set JAVA_HOME=&quot;$(SolutionDir)\java\jdk&quot;&#x0D;&#x0A;set PATH=&quot;$(SolutionDir)\java\ant\bin&quot;;%PATH%;&#x0D;&#x0A;cd src\java&#x0D;&#x0A;ant jar&#x0D;&#x0A;cd  ..\..&#x0D;&#x0A;"\r
                        />\r
                </Configuration>\r
        </Configurations>\r
                        UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"\r
                        >\r
                        <File\r
+                               RelativePath=".\src\c\addToClasspath.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
                                RelativePath=".\src\c\DllmainJvm.c"\r
                                >\r
                        </File>\r
                                >\r
                        </File>\r
                        <File\r
+                               RelativePath=".\sci_gateway\c\sci_javaclasspath.c"\r
+                               >\r
+                       </File>\r
+                       <File\r
                                RelativePath=".\sci_gateway\c\sci_jvm_version.c"\r
                                >\r
                        </File>\r
                        UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"\r
                        >\r
                        <File\r
+                               RelativePath=".\includes\addToClasspath.h"\r
+                               >\r
+                       </File>\r
+                       <File\r
                                RelativePath=".\includes\getScilabJavaVM.h"\r
                                >\r
                        </File>\r
                                >\r
                        </File>\r
                </Filter>\r
+               <Filter\r
+                       Name="Ant"\r
+                       >\r
+                       <File\r
+                               RelativePath=".\src\java\build.xml"\r
+                               >\r
+                       </File>\r
+               </Filter>\r
+               <Filter\r
+                       Name="Java classes"\r
+                       >\r
+                       <File\r
+                               RelativePath=".\src\java\org\scilab\modules\jvm\ClassPath.java"\r
+                               >\r
+                       </File>\r
+               </Filter>\r
                <File\r
                        RelativePath=".\jvm.iss"\r
                        >\r
index 7dbfa4c..7e03ba1 100644 (file)
 #endif\r
 #include "gw_jvm.h"\r
 #include "stack-c.h"\r
+#include "scilabmode.h"\r
+#include "Scierror.h"\r
 /*-----------------------------------------------------------------------------------*/\r
 typedef int (*jvm_Interf) __PARAMS((char *fname,unsigned long l));\r
-\r
+/*-----------------------------------------------------------------------------------*/\r
 typedef struct table_struct\r
 {\r
        jvm_Interf f;    /** function **/\r
@@ -23,28 +25,38 @@ static jvmTable Tab[]=
 {\r
        {C2F(sci_with_embedded_jre),"with_embedded_jre"},\r
        {C2F(sci_jvm_version),"jvm_version"},\r
+       {C2F(sci_javaclasspath),"javaclasspath"}\r
 };\r
 /*-----------------------------------------------------------------------------------*/\r
 int C2F(gw_jvm)(void)\r
 {  \r
        Rhs = Max(0, Rhs);\r
 \r
-#ifdef _MSC_VER\r
-#ifndef _DEBUG\r
-       _try\r
+       if ( (getScilabMode() != SCILAB_NWNI) )\r
        {\r
+#ifdef _MSC_VER\r
+       #ifndef _DEBUG\r
+               _try\r
+               {\r
+                       (*(Tab[Fin-1].f)) (Tab[Fin-1].name,(unsigned long)strlen(Tab[Fin-1].name));\r
+               }\r
+               _except (EXCEPTION_EXECUTE_HANDLER)\r
+               {       \r
+                       ExceptionMessage(GetExceptionCode(),Tab[Fin-1].name);\r
+               }\r
+       #else\r
                (*(Tab[Fin-1].f)) (Tab[Fin-1].name,(unsigned long)strlen(Tab[Fin-1].name));\r
-       }\r
-       _except (EXCEPTION_EXECUTE_HANDLER)\r
-       {       \r
-               ExceptionMessage(GetExceptionCode(),Tab[Fin-1].name);\r
-       }\r
-#else\r
-       (*(Tab[Fin-1].f)) (Tab[Fin-1].name,(unsigned long)strlen(Tab[Fin-1].name));\r
-#endif\r
+       #endif\r
 #else\r
-       (*(Tab[Fin-1].f)) (Tab[Fin-1].name,(unsigned long)strlen(Tab[Fin-1].name));\r
+               (*(Tab[Fin-1].f)) (Tab[Fin-1].name,(unsigned long)strlen(Tab[Fin-1].name));\r
 #endif\r
+       }\r
+       else\r
+       {\r
+               Scierror(999,"jvm interface disabled -nogui or -nwni mode.\r\n");\r
+       }\r
+\r
+\r
        return 0;\r
 }\r
 /*-----------------------------------------------------------------------------------*/\r
diff --git a/scilab/modules/jvm/sci_gateway/c/sci_javaclasspath.c b/scilab/modules/jvm/sci_gateway/c/sci_javaclasspath.c
new file mode 100644 (file)
index 0000000..e600ce2
--- /dev/null
@@ -0,0 +1,46 @@
+/*-----------------------------------------------------------------------------------*/\r
+/**\r
+ * @author Allan CORNET INRIA 2007\r
+ */\r
+/*-----------------------------------------------------------------------------------*/\r
+#include "gw_jvm.h"\r
+#include "MALLOC.h"\r
+#include "machine.h"\r
+#include "stack-c.h"\r
+#include "sciprint.h"\r
+#include "Scierror.h"\r
+#include "addToClasspath.h"\r
+/*-----------------------------------------------------------------------------------*/\r
+int C2F(sci_javaclasspath) _PARAMS((char *fname,unsigned long fname_len))\r
+{\r
+       CheckRhs(1,1);\r
+       CheckLhs(0,1);\r
+\r
+       if (GetType(1) == sci_strings)\r
+       {\r
+               static int l1=0,n1=0,m1=0;\r
+               int i=0;\r
+               BOOL bOK=FALSE;\r
+               char **CLASSPATHS=NULL;\r
+\r
+               GetRhsVar(1,"S",&m1,&n1,&CLASSPATHS);\r
+\r
+               for (i = 0; i<m1*n1 ;i++)\r
+               {\r
+                       bOK=addToClasspath(CLASSPATHS[i]);\r
+                       if (!bOK)\r
+                       {\r
+                               Scierror(999,"could not add URL to system classloader : %s.\r\n",CLASSPATHS[i]);\r
+                               return 0;\r
+                       }\r
+               }\r
+               LhsVar(0) = 0;\r
+               C2F(putlhsvar)();       \r
+       }\r
+       else\r
+       {\r
+               Scierror(999,"invalid parameter(s).\r\n");\r
+       }\r
+       return 0;\r
+}\r
+/*-----------------------------------------------------------------------------------*/\r
index d7c7cc6..7bc48c1 100644 (file)
@@ -25,4 +25,5 @@
 \r
 <PRIMITIVE gatewayId="52" primitiveId="1" primitiveName="with_embedded_jre" />\r
 <PRIMITIVE gatewayId="52" primitiveId="2" primitiveName="jvm_version" />\r
+<PRIMITIVE gatewayId="52" primitiveId="3" primitiveName="javaclasspath" />\r
 </GATEWAY>\r
index e34dc6f..9b42f47 100644 (file)
@@ -78,12 +78,12 @@ BOOL startJVM(char *SCI_PATH)
                        strlen(DEFAULT_SCILAB_CLASSPATH)+\r
                        strlen(PATH_SEPARATOR)+\r
                        strlen(USER_CLASSPATH)+\r
-                        strlen(PATH_SEPARATOR)+\r
-                        strlen(SCI_PATH)  +\r
-                        strlen(GRAPHICS_CLASSPATH));\r
+            strlen(PATH_SEPARATOR)+\r
+            strlen(SCI_PATH)  +\r
+            strlen(JVM_CLASSPATH));\r
 \r
                JAVACLASSPATH=(char*) MALLOC( sizeof(char)*     ( length_JAVACLASSPATH +1) );\r
-               sprintf(JAVACLASSPATH,"-Djava.class.path=%s%s%s%s%s%s%s",SCI_PATH,DEFAULT_SCILAB_CLASSPATH,PATH_SEPARATOR,USER_CLASSPATH,PATH_SEPARATOR,SCI_PATH,GRAPHICS_CLASSPATH);\r
+               sprintf(JAVACLASSPATH,"-Djava.class.path=%s%s%s%s%s%s%s",SCI_PATH,DEFAULT_SCILAB_CLASSPATH,PATH_SEPARATOR,USER_CLASSPATH,PATH_SEPARATOR,SCI_PATH,JVM_CLASSPATH);\r
 \r
                length_JAVALIBRARYPATH = (int)( strlen("-Djava.library.path=%s%s/lib%s%s%s")+\r
                        strlen(SCI_PATH)+\r
index b4af052..95a7de6 100644 (file)
@@ -28,7 +28,7 @@
 #endif\r
 /*-----------------------------------------------------------------------------------*/ \r
 #define USER_CLASSPATH "."\r
-#define GRAPHICS_CLASSPATH "/java/jar/modules/graphics.jar"\r
+#define JVM_CLASSPATH "/java/jar/modules/jvm.jar"\r
 /*-----------------------------------------------------------------------------------*/ \r
 #endif /*  __JVM_COMMONS_H__ */\r
 /*-----------------------------------------------------------------------------------*/ \r
diff --git a/scilab/modules/jvm/src/c/addToClasspath.c b/scilab/modules/jvm/src/c/addToClasspath.c
new file mode 100644 (file)
index 0000000..af8a94c
--- /dev/null
@@ -0,0 +1,38 @@
+/*-----------------------------------------------------------------------------------*/\r
+/* INRIA 2007 */\r
+/* Allan CORNET */\r
+/*-----------------------------------------------------------------------------------*/ \r
+#include "addToClasspath.h"\r
+#include "jni.h"\r
+#include "getScilabJNIEnv.h"\r
+/*-----------------------------------------------------------------------------------*/ \r
+BOOL addToClasspath(char *classpathstring)\r
+{\r
+       BOOL bOK=FALSE;\r
+\r
+       if (classpathstring)\r
+       {\r
+               JNIEnv * currentENV = getScilabJNIEnv();\r
+\r
+               jclass cls=NULL;\r
+               jmethodID mid=NULL;\r
+\r
+               if (currentENV)\r
+               {\r
+                       cls = (*currentENV)->FindClass(currentENV, "org/scilab/modules/jvm/ClassPath");\r
+                       if (cls)\r
+                       {\r
+                               mid = (*currentENV)->GetStaticMethodID(currentENV, cls, "addFile","(Ljava/lang/String;)V");\r
+                               if (mid)\r
+                               {\r
+                                       jstring jstr;\r
+                                       jstr = (*currentENV)->NewStringUTF(currentENV,classpathstring);\r
+                                       (*currentENV)->CallStaticObjectMethod(currentENV,cls, mid,jstr);\r
+                                       bOK=TRUE;\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+       return bOK;\r
+}\r
+/*-----------------------------------------------------------------------------------*/ \r
diff --git a/scilab/modules/jvm/src/java/build.xml b/scilab/modules/jvm/src/java/build.xml
new file mode 100644 (file)
index 0000000..90fd480
--- /dev/null
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<!--\r
+Allan CORNET\r
+INRIA 2007\r
+-->\r
+<project name="jvm" default="compile">\r
+\r
+   <property name="dist"  location="../../../../java/jar/modules" />\r
+   \r
+   <description>\r
+        build jvm modules\r
+    </description>\r
+    \r
+    <target name="init">\r
+                       <!-- Create the time stamp -->\r
+                       <tstamp/>\r
+               </target>    \r
+\r
+    <target name="clean" description="clean sources">\r
+        <delete dir="build"/>\r
+        <delete file="${dist}/jvm.jar"/>\r
+    </target>\r
+\r
+    <target name="compile" description="build sources" depends="init">\r
+    \r
+        <mkdir dir="build/classes"/>\r
+        <javac srcdir="org" destdir="build/classes"/>\r
+    </target>\r
+\r
+    <target name="jar" description="do .jar file" depends="compile">\r
+        <jar destfile="${dist}/jvm.jar" basedir="build/classes">\r
+            <manifest>\r
+                <attribute name="ClassPath" value="org.scilab.modules.jvm.ClassPath"/>\r
+                \r
+            </manifest>\r
+        </jar>\r
+    </target>\r
+\r
+</project>\r
diff --git a/scilab/modules/jvm/src/java/org/scilab/modules/jvm/ClassPath.java b/scilab/modules/jvm/src/java/org/scilab/modules/jvm/ClassPath.java
new file mode 100644 (file)
index 0000000..141f80a
--- /dev/null
@@ -0,0 +1,42 @@
+/*-----------------------------------------------------------------------------------*/\r
+/**\r
+* Loading classes at runtime.\r
+*/\r
+/*-----------------------------------------------------------------------------------*/\r
+package org.scilab.modules.jvm;\r
+/*-----------------------------------------------------------------------------------*/ \r
+import java.lang.reflect.*;\r
+import java.io.*;\r
+import java.net.*;\r
+/*-----------------------------------------------------------------------------------*/ \r
+public class ClassPath {\r
\r
+private static final Class[] parameters = new Class[]{URL.class};\r
\r
+public static void addFile(String s) throws IOException {\r
+       File f = new File(s);\r
+       addFile(f);\r
+}\r
+/*-----------------------------------------------------------------------------------*/ \r
+public static void addFile(File f) throws IOException {\r
+       addURL(f.toURL());\r
+}\r
+/*-----------------------------------------------------------------------------------*/  \r
+public static void addURL(URL u) throws IOException {\r
+               \r
+       URLClassLoader sysloader = (URLClassLoader)ClassLoader.getSystemClassLoader();\r
+       Class sysclass = URLClassLoader.class;\r
\r
+       try {\r
+               Method method = sysclass.getDeclaredMethod("addURL",parameters);\r
+               method.setAccessible(true);\r
+               method.invoke(sysloader,new Object[]{ u });\r
+       } catch (Throwable t) {\r
+               t.printStackTrace();\r
+               throw new IOException("Error, could not add URL to system classloader");\r
+       }\r
+}\r
+/*-----------------------------------------------------------------------------------*/  \r
+}\r
+/*-----------------------------------------------------------------------------------*/ \r
+\r