Wednesday, December 5, 2012

Projects Integration (C/C++, Java, Fortran)

Closure IDE

Projects Integration (C/C++, Java, Fortran)

This tutorial shows how to setup a dual-language project such as Maple/Java or Maple/C in Maple IDE. In the end of the article you can find some links for further reading.

Maple Connectivity

The integration of Maple projects with other Eclipse projects is designed for seamless development and building processes of your C, Fortran, or Java code for Maple using External Calling package.

Maple Project can be mixed with Eclipse JDT - Java Project, Eclipse CDT - C/C++ Project and Eclipse PTP - Fortran Project. In the tutorial we use Maple with Java language.

External Calling of Java code

In this tutorial we develop a Java/Maple project consisting of:

  • A Java class, GeometryUtils, with methods circleArea() and rectangleArea(). The class calculates area for the shapes (circle, rectangle). In the tutorial we use super simple Java class to concentrate on the subject.
  • A Maple module, GeometryModule, with public variables circleArea and rectangleArea which call corresponding Java methods directly from the compiled Java class GeometryUtils using define_external Maple command.
  1. Create Java project and GeometryUtils Java class.

    GeometryUtils is a simple Java class that uses java.lang.Math class.
    public class MathUtil {
    public static double circleArea(double radius) {
    return Math.PI * Math.pow(radius, 2);

    public static double rectangleArea(double a, double b) {
    return a * b;
  2. From the project's pop-up menu (right-click), select Maple > Add Maple Nature.

    The project becomes a dual Maple Project (Maple/Java) with the default Libname/Build Path.

  3. Create a new Maple source folder named modules and add GeometryModule Maple file with the following module:
    GeometryModule := module()
    export circleArea, rectangleArea
    description "Maple External Call - Java - Geometry Module"
    circleArea := define_external('circleArea', CLASS = "", CLASSPATH = "D:/workspaces/runtime-EclipseApplication/", JAVA, radius::float[8], RETURN::float[8]); 

    rectangleArea := define_external('rectangleArea ', CLASS ""CLASSPATH "D:/workspaces/runtime-EclipseApplication/"JAVAa::float[8], b::float[8], RETURN::float[8]);  
    end module;

    Do not forget to replace CLASSPATH value with the actual output folder path of your Java project where compiled Java classes are located (by default is bin folder of your project).

  4. From a project's pop-up menu (right-click), select Run as > Maple.

  5. Maple runs in the Eclipse console and we can use our Java methods as normal Maple procedures defined in the module.

Future enhancements

For the next update for the Maple IDE, we plan to add three export wizards for Java, C and Fortran projects. The wizards automatically generate a Maple module with external calling commands based on the selected Java class, C or Fortran shared library.

Possible issues

java.lang.UnsupportedClassVersionError: ... : Unsupported major.minor version 51.0

The error means you compiled the Java class with a newer version of Java and are trying to run with an older version, such as compiling with Java 7 but trying to run in Java 5 environment. Currently Maple uses Java 5 environment.

To fix the error, do the following:

  1. From a project's pop-up menu (right-click), select Properties > Java Build Path.
    Select Libraries tab.
  2. Select JRE System Library and click Edit button.
  3. From the execution environment drop-down menu choose J2SE-1.5. Click OK

java.lang.ClassNotFoundException: GeometryUtils

The error means the Java class cannot be found because of an incorrect name or a wrong path in the command.
To fix the error, check CLASS and CLASSPATH options of the define_external command.

  1. CLASS must contain fully qualified name of the Java class, such as, but not GeometryUtils.
  2. CLASSPATH must contain the directory where the classes reside.


No comments: