Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
5.4.1 - 日本語

Change language to:
English - Français - Português - Русский

Please note that the recommended version of Scilab is 2024.0.0. This page might be outdated.
See the recommended documentation of this function

Scilab help >> Java Interface > 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:

  • 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 code based on Javasci v2, the path to the following libraries has to be added in the classpath:

  • org.scilab.modules.javasci.jar
  • org.scilab.modules.types.jar

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

Then, 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 argurment 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.

The compilation is the quite the same as in Linux environment. The path to the following libraries has to be added in the classpath:

  • org.scilab.modules.javasci.jar
  • org.scilab.modules.types.jar

So, 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\javasci\jar\org.scilab.modules.javasci.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%

Then, 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 environnement 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;

class BasicExample {

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

See Also

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

Copyright (c) 2022-2023 (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:
Tue Apr 02 17:37:35 CEST 2013