How to connect Java and Maple using OpenMaple



1. Setup Runtime Environment:

Open your environment file (example in Linux with .bashrc) add these code to initialize environment and library:

. $MAPLE/bin/maple -norun    # for maple config environment
export MAPLE=/home/your_user_name/opt/maple2015
export CLASSPATH=$CLASSPATH:$MAPLE/java/externalcall.jar
export CLASSPATH=$CLASSPATH:$MAPLE/java/jopenmaple.jar

2. Example code.

Create Test.java file and add these code.

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" );
           return;
       }
       System.out.println( "Done" );
   }
}

Run by type in terminal:

$ javac Test.java
$ java Test

Screenshot-from-2017-05-09 22:42:44.png

Notice: With Netbean, Eclipse or other IDEs. If it doesn’t work. You should add Maple library *.jar file above into your project.

Ref: https://www.maplesoft.com/support/help/maple/view.aspx?path=OpenMaple/Java/Examples

Leave a Reply

Your email address will not be published. Required fields are marked *