Introduction
The mosjvm module allows you to create a Java virtual machine within the same process running Mosel, and call Java methods from within a Mosel model. For example:
javaReturnString := jvmcallstr('com.fico.testpackage.TestClass.myTestFunction', functionArg1, functionArg2, functionArg3) writeln("2+5=", jvmcallint('com.fico.testpackage.SimpleMathOperations.addTwoValues', 2, 5))
In this way, you can interact with pre-existing Java libraries from your Mosel model. However, please note that there are some drawbacks to instantiating a Java virtual machine in the same process as the Mosel virtual machine, and developers are advised to consider other approaches (for example: deploying your Java classes to a Tomcat webserver and interacting with them using standard webservice requests) before building a solution based upon mosjvm.
The developer is advised to read the later chapter which goes into some detail about the limitations of this module. But the most major limitations to be aware of are:
- This module is only available for Windows and Linux.
- Java 8 or 11 must be installed on the machine running the model. Other versions of Java are not supported at this time. Distributions other than Oracle Java, OpenJDK and Amazon Corretto are not supported.
- This module can only run compiled Java .class files (either directly as files or built into a .jar). Java source code must be compiled by other tools.