- Knowledge of Java development
- Knowledge of Eclipse or another Java IDE
- Knowledge of Mirth Connect
Many Mirth professionals are unaware that they can write their own custom Java libraries to leverage in their channels. A jar is simply a file that contains Java functions (methods) and classes that are available to Mirth developers for use.
You may be wondering where you can create or obtain such a jar file to use in your Mirth channels. This will be covered in a later section; however, keep in mind that this article is not intended to cover Java development in its entirety. If you are developing in Mirth every day, you should consider learning Java.
There are several things you need to set up in order to reference your Java code in your Mirth Connect channels. You need to create your jar file. You need to deploy your jar file. Finally, you need to use your jar file.
Creating Your Jar File
Typically, Java developers use an IDE (Integrated Development Environment) to create a jar file. A couple of common Java IDEs include Eclipse and NetBeans.
Eclipse will be used in this post to demonstrate the process of creating a jar file.
1. Locate your Eclipse project
2. Right-click on your project and select Export
3. Expand the Java option and select Jar file. Afterwards, click Next >
4. Select the ‘Export Java source files and resources’ option. Type in the name for your jar and choose an export directory. Make sure that the ‘.classpath’ and ‘.project’ options are selected.
5. Click Finish. You now have your jar file in the export directory that you specified.
Deploying Your Jar File
Now that you have a jar file, how do you get it to place nice with your Mirth Connect installation?
Jar files must be present in the custom-lib folder in order to be used with Mirth Connect. The custom-lib folder can be found in the root of the Mirth Connect installation folder (See below).
Place your jar file inside custom-lib.
Next, log into Mirth and select Settings on the left-hand side.
Select the Resources tab.
Select the Default Resource.
Select Reload Resource on the left-hand side under Resource Tasks.
Click Yes on the dialog pop up.
You should now see all your jar files under Loaded Libraries.
Utilizing Your Jar File
Developers are typically looking to do one of two things when utilizing a custom jar file in Mirth.
- Call a public static method
- Instantiate a Java Object
In either scenario, developers need to be aware of the syntax in order to reference their jar file correctly. Below is an example of calling a public static method in Mirth Connect.
var result = new Packages.packageName.className.methodName();
In the code above, packageName, className, and methodName will all be specific to your jar file. Make sure to take a peek at your Java project if you don’t know any one of these. Using the example from Eclipse, the package name would be MirthDev and the class name would also be MirthDev.
Creating an object works the exact same way except that the method name is the constructor.
var result = new Packages.packageName.className.constructor();
Utilizing Java code in your Mirth Connect channels is a massive hack that every Mirth professional should take advantage of. If you have background in Java development, leverage your knowledge of Mirth Connect to supercharge your channels.