Using Built-In Methods from an External Java Library
When developing an external Java® library to be used in the Application Builder, it is possible to call the built-in methods from the external library. In order to do so, the com.comsol.api JAR-file needs to be added to the project build path, and the classes that call the methods need to extend the ApplicationLanguageBase class. The following steps explain how to create a simple example JAR library when using the Eclipse® integrated development environment:
1
2
Create a new Java® project. Enter JavaLibDemo as the project name and click Next.
3
Go to the Libraries tab and click Add External JARs. Add the JAR-file com.comsol.api_1.0.0.jar from the plugins directory under the COMSOL Multiphysics installation directory; for example
C:\Program Files\COMSOL\COMSOL64\Multiphysics\plugins
4
Click Finish.
5
Right-click the src folder in your Eclipse project and select New > Package. Enter demo as the package name and click Finish.
6
Right-click the demo package in your Eclipse project and select New > Class. Enter Hello as the class name.
7
Click on Superclass > Browse and select ApplicationLanguageBase. Click OK and Finish.
8
In the editor window for the Hello class, add the following method and save the file:
  public static void hello() {
    alert("Hello!");
  }
9
Right-click the JavaLibDemo project and select Export > Java > JAR file. Select the export destination JAR-file and click Finish.
10
11
In the Application Builder, under the application tree, right-click Libraries and select External Java Library. In the Settings window, click Browse and select the JAR-file previously exported from Eclipse®.
12
13
  Hello.hello();
14
Click Test Application and click the button in the application to verify that the alert method is invoked.