Building and Running a Java OpenMaple Application
Packages
Building
Running
The Java OpenMaple classes are provided in the com.maplesoft.openmaple package. This package is contained within the Maple.jar file. A second package, com.maplesoft.externalcall.MapleException is also required for Java OpenMaple. This class is in the externalcall.jar file. For documentation on the contents of the com.maplesoft.openmaple package, see OpenMaple/Java/API. For information about com.maplesoft.externalcall.MapleException, see ExternalCalling/Java/MapleException.
These jar files are in the java directory of your Maple installation. The directory that Maple is installed in can be found by calling kernelopts( mapledir ).
kernelopts( mapledir );
C:\Program Files\Maple 2023
In the following sections we will refer to this directory as <MAPLEDIR>. Different platforms and installation locations will effect this directory, so you should call kernelopts( mapledir ) to determine the correct location on your machine.
To build a Java OpenMaple application the two required jar files, Maple.jar and externalcall.jar, must be in the classpath. Simply specify these files in a command-line argument to the Java compiler. In general, the -classpath argument should work. You will need to have write permissions for the current directory as this command will create a new file.
Windows
javac -classpath "<MAPLEDIR>\java\externalcall.jar;<MAPLEDIR>\java\Maple.jar" app.java
macOS and Linux
javac -classpath "<MAPLEDIR>/java/externalcall.jar:<MAPLEDIR>/java/Maple.jar" app.java
Running a Java OpenMaple application requires loading a native library. This native library provides the link between Maple and Java. The Java Virtual Machine automatically loads the required library; however, it needs to be told where to find this library. By default, the native library is installed in the Maple binary directory. To determine this location, call kernelopts( bindir ).
kernelopts( bindir );
C:\Program Files\Maple 2023\bin.X86_64_WINDOWS
Different platforms and installation locations will effect the directory you need to use, so you should call kernelopts( bindir ) to determine the correct location. We will refer to this directory as <BINDIR> in the following examples.
To tell the Java Virtual Machine to look in this directory, you need to add <BINDIR> to a platform specific environment variable. In addition on macOS and Linux, the MAPLE environment variable needs to be set to the value <MAPLEDIR> we defined above.
In Windows, you need to add <BINDIR> to the PATH environment variable
set PATH=%PATH%;<BINDIR>
Linux
On Linux, you need to add at least <BINDIR> to the LD_LIBRARY_PATH environment variable and set the MAPLE environment variable. For a complete list of directories to add, run getenv(LD_LIBRARY_PATH); in Maple and use that exact value.
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:<BINDIR>"
export MAPLE="<MAPLEDIR>"
macOS
On macOS, you need to add at least <BINDIR> to the DYLD_LIBRARY_PATH environment variable and set the MAPLE environment variable. For a complete list of directories to add, run getenv(DYLD_LIBRARY_PATH); in Maple and use that exact value.
export DYLD_LIBRARY_PATH="$DYLD_LIBRARY_PATH:<BINDIR>"
As with the compiler, the Java Virtual Machine must have the Maple.jar and externalcall.jar files added to the classpath, along with the directory containing the test.class file created above. Once again, using the -classpath command-line argument is recommended. This example assumes that the test.class file is stored in the current directory.
Additionally the -Xss option must be used to specify the default amount of stack memory Java will allow the Maple calls to use. The default of 1MB is too low for Maple and may lead to segmentation faults. The higher the value, the deeper Maple will be allowed to recurse during computations.
java -Xss100M -classpath "<MAPLEDIR>\java\externalcall.jar;<MAPLEDIR>\java\Maple.jar;." test
java -Xss100M -classpath "<MAPLEDIR>/java/externalcall.jar:<MAPLEDIR>/java/Maple.jar:." test
Before beginning development of a Java OpenMaple application, ensure that the simple example from the examples page can be built and executed. Once this works, a more complex Java OpenMaple application can be built the same way.
See Also
OpenMaple
OpenMaple/Java/API
OpenMaple/Java/Engine
OpenMaple/Java/Examples
trademark
Download Help Document