Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
2025.0.0 - Français


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:

  • In the binary version of Scilab, SCI will point to /path/to/scilab/share/scilab/

  • In the source tree of Scilab, SCI will point to the root of the source tree /path/to/scilab/source/tree/

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

  • org.scilab.modules.javasci.jar (required for all Javasci applications)
  • org.scilab.modules.types.jar (if the application uses Javasci types)

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:

  • In the LD_LIBRARY_PATH:

    • In the binary version of Scilab, LD_LIBRARY_PATH will point to /path/to/scilab/lib/scilab/ and /path/to/scilab/lib/thirdparty/

    • In the source tree of Scilab, LD_LIBRARY_PATH will point to the root of the source tree /path/to/scilab/modules/javasci/.libs/, /path/to/scilab/modules/types/.libs/ and /path/to/scilab/.libs/

    And the application is run with the command line:

    java -cp $SCI/modules/javasci/jar/org.scilab.modules.javasci.jar:$SCI/modules/types/jar/org.scilab.modules.types.jar:. BasicExample
  • Or as argument of java, in the command line:

    java -Djava.library.path=/path/to/libjavasci/:/path/to/scilab/lib/thirdparty/ -cp $SCI/modules/javasci/jar/org.scilab.modules.javasci.jar:$SCI/modules/types/jar/org.scilab.modules.types.jar:. BasicExample

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:

  • org.scilab.modules.javasci.jar (required for all Javasci applications)
  • org.scilab.modules.types.jar (if the application uses Javasci types)

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:

  • SCI_DISABLE_TK=1 disables Tk (Tcl's GUI)

  • SCI_JAVA_ENABLE_HEADLESS=1 launches Java in headless mode (no AWT/Swing)

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 >>

Copyright (c) 2022-2024 (Dassault Systèmes)
Copyright (c) 2017-2022 (ESI Group)
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Thu Oct 24 11:16:04 CEST 2024