<< Interface avec Java Interface avec Java javasci >>

Scilab Help >> Interface avec Java > Compile and run with javasci v2

Compile and run with javasci v2

How to compile a Java application using Javasci v2

Linux/Unix/MacOSX

On Linux/Unix/MacOSX, Scilab needs the SCI global variable to be set:

To compile a Java application using Javasci v2, the path to the following libraries may have to be added in the classpath:

To compile the example code (the code is further in this page), the command line is:

javac -cp $SCI/modules/javasci/jar/org.scilab.modules.javasci.jar:$SCI/modules/types/jar/org.scilab.modules.types.jar:. BasicExample.java

To launch the Java application, the path to the libjavasci native library needs to be provided, either:

Windows

In this paragraph we suppose Scilab is installed in the directory C:\Program Files\scilab-XXXX (where XXXX is the version of Scilab, for example "5.4.0").

On windows, no specific environment variable needs to be defined.

To compile a Java application using Javasci v2, the path to the following libraries may have to be added in the classpath:

To compile the example code, the command line is:

javac -cp "C:\Program Files\scilab-XXXX\modules\javasci\jar\org.scilab.modules.javasci.jar;C:\Program Files\scilab-XXXX\modules\types\jar\org.scilab.modules.types.jar;." BasicExample.java

For execution, the path to the native library libjavasci.dll and to its dependencies must be added in the PATH environment variable. All the needed libraries are in the "bin" folder, so the command line is:

set PATH="C:\Program Files\scilab-XXXX\bin";%PATH%

To launch the Java application, the command line is quite the same as for Linux:

java -cp "C:\Program Files\scilab-XXXX\modules\javasci\jar\org.scilab.modules.javasci.jar;C:\Program Files\scilab-XXXX\modules\types\jar\org.scilab.modules.types.jar;." BasicExample

Options

Optional options to launch java : -Djava.compiler=JIT -Xmx256m

(With these arguments, javasci is started with same initial options like the standard scilab).

Note that two environment variables are taken in account for specific needs:

Examples

// A simple Java example
// javasci v2
// Filename: BasicExample.java

import org.scilab.modules.javasci.Scilab;
import org.scilab.modules.types.ScilabType;

class BasicExample {

    public static void main(String[] args) {
        try {
            Scilab sci = new Scilab();
            sci.open();
            sci.exec("a=cos(%pi)*sin(%pi^2);");
            ScilabType a = sci.get("a");
            System.out.println("a = " + a);
        } catch (org.scilab.modules.javasci.JavasciException e) {
            System.err.println("Could not find variable type: " + e.getLocalizedMessage());
        }
   }
}

See also


Report an issue
<< Interface avec Java Interface avec Java javasci >>