Saturday, May 28, 2022
Home Integration/Interfaces Reference a Custom Jar File in Mirth Connect Now

Reference a Custom Jar File in Mirth Connect Now

Prerequisites

  • 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();

Once the method call or object instantiation is complete, developers can continue writing JavaScript to complete the remaining logic.


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.

RELATED ARTICLES

Why You Must Learn Mirth Connect’s User API Now

Prerequisites Basic knowledge of Mirth ConnectBasic knowledge of JavaScriptBasic knowledge of software documentation and APIsBasic knowledge of Java development NextGen provides several different APIs (Application Programming...

Leverage Mirth’s Channel Scripts Now

Prerequisites Basic knowledge of Mirth ConnectBasic knowledge of JavaScript Each Mirth Connect channel gives you the ability to leverage four different scripts that have different triggers,...

Get to Know Mirth’s Configuration Map Now

What exactly is Mirth's configuration map? And how should Mirth developers take advantage of it to create more maintainable channels? Before diving in, it should...

Most Popular

Mirth Connect Extensions: What You Need to Know

Prerequisistes Basic Knowledge of Mirth Connect Overview Users can navigate to Mirth Connect's Extensions screen by selecting Extensions on the left-hand side. You should now see the following...

Take a Tour of System Settings in Mirth Connect Now

Prerequisites Basic Knowledge of Mirth Connect Introduction Mirth Connect has a multitude of system settings that are available for configuration. In larger companies, there will often be...

Why You Must Master Mirth’s Message Template Tool Today

Prerequisuites Basic Knowledge of Mirth ConnectKnowledge of Programming in Mirth Connect Introduction When writing scripts in Mirth Connect, you have a message template tool that allows you...

Make Sense of HL7 v2 Messages Effortlessly Now

Prerequisites Beginner Knowledge of HL7 Introduction If you've been in Healthcare Information Technology for any period of time, you have definitely heard of HL7 (Health Level 7)....

Recent Comments