Maple Professionel
Maple Académique
Maple Edition Étudiant
Maple Personal Edition
Maple Player
Maple Player for iPad
MapleSim Professionel
MapleSim Académique
Maple T.A. - Suite d'examens de classement
Maple T.A. MAA Placement Test Suite
Möbius - Didacticiels de mathématiques en ligne
Machine Design / Industrial Automation
Aéronautique
Ingénierie des véhicules
Robotics
Energie
System Simulation and Analysis
Model development for HIL
Modélisation du procédé pour la conception de systèmes de contrôle
Robotics/Motion Control/Mechatronics
Other Application Areas
Enseignement des mathématiques
Enseignement de l’ingénierie
Enseignement secondaire et supérieur (CPGE, BTS)
Tests et évaluations
Etudiants
Modélisation financière
Recherche opérationnelle
Calcul haute performance
Physique
Webinaires en direct
Webinaires enregistrés
Agenda des évènements
Forum MaplePrimes
Blog Maplesoft
Membres Maplesoft
Maple Ambassador Program
MapleCloud
Livres blancs techniques
Bulletin électronique
Livres Maple
Math Matters
Portail des applications
Galerie de modèles MapleSim
Cas d'Etudes Utilisateur
Exploring Engineering Fundamentals
Concepts d’enseignement avec Maple
Centre d’accueil utilisateur Maplesoft
Centre de ressources pour enseignants
Centre d’assistance aux étudiants
Java OpenMaple Examples
A Simple Example
The following Java class starts a Maple session, evaluates a single expression, and then exits. It uses the following classes: Engine, EngineCallBacksDefault and MapleException.
For general instructions for running Java OpenMaple applications, see running.
import com.maplesoft.openmaple.*;
import com.maplesoft.externalcall.MapleException;
class test
{
public static void main( String args[] )
String a[];
Engine t;
int i;
a = new String[1];
a[0] = "java";
try
t = new Engine( a, new EngineCallBacksDefault(), null, null );
t.evaluate( "int( x,x );" );
}
catch ( MapleException e )
System.out.println( "An exception occurred\n" );
return;
System.out.println( "Done\n" );
This example can be copied directly from this page and pasted into a file named test.java (it is also available in the samples/OpenMaple/Java/simple directory in your Maple installation).
In the following examples, assume that <JDKBINDIR> refers to the directory in which your Java development tools are installed. If your Java development tools are in your default path, you don't need to to worry about specifying the tool's location.
You'll need to know your Maple installation location. We will refer to this location as <MAPLEDIR>. You can determine your installation location by calling kernelopts( mapledir ) in Maple.
Compiling the Java file
We first need to compile the java source file into a class file.
Windows
<JDKBINDIR>\javac -classpath "<MAPLEDIR>\java\externalcall.jar;<MAPLEDIR>\java\jopenmaple.jar" test.java
Apple OS X, Linux and Solaris
<JDKBINDIR>/javac -classpath "<MAPLEDIR>/java/externalcall.jar:<MAPLEDIR>/java/jopenmaple.jar" test.java
There should now be a file called test.class in the current directory.
Executing
Before this example can be executed, the Java Virtual Machine must be told where to look for the Java OpenMaple native library. This library connects Java to Maple. It is located in the binary directory of your Maple installation. To determine which directory this is on your machine, call kernelopts( bindir ) in Maple. We will refer to this location as <BINDIR>
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 Apple OS X, Linux and Solaris, 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 and Solaris
On Linux and Solaris, you need to add <BINDIR> to the LD_LIBRARY_PATH environment variable and set the MAPLE environment variable.
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:<BINDIR>"
export MAPLE="<MAPLEDIR>"
Apple OS X
On Apple OS X, you need to add <BINDIR> to the DYLD_LIBRARY_PATH environment variable and set the MAPLE environment variable.
export DYLD_LIBRARY_PATH="$DYLD_LIBRARY_PATH:<BINDIR>"
As with the compiler, the Java Virtual Machine must have the jopenmaple.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.
java -classpath "<MAPLEDIR>\java\externalcall.jar;<MAPLEDIR>\java\jopenmaple.jar;." test
java -classpath "<MAPLEDIR>/java/externalcall.jar:<MAPLEDIR>/java/jopenmaple.jar:." test
If all went well, executing the line above should produce the following output.
1/2*x^2
Done
This brief example can be found in the samples/OpenMaple/Java/simple directory. More interesting and complex examples can be found in the subdirectories of samples/OpenMaple/Java.
See Also
OpenMaple, OpenMaple/Java/Algebraic, OpenMaple/Java/API, OpenMaple/Java/Engine, OpenMaple/Java/running, trademarks
Download Help Document