web stats
import java libraries - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 03-24-2017, 05:58 AM
ryadical ryadical is offline
OBX.1 Kenobi
 
Join Date: Aug 2016
Posts: 33
ryadical is on a distinguished road
Default import java libraries

I appologize if this sounds like a stupid question, java is not my primary language. Is there a way to import java libraries so that you don't have to type the full namespace out?

For example, can I import
org.apache.commons.lang3.StringUtils so that I don't have to type out org.apache.commons.lang3.StringUtils.defaultString every time I want to use that method?
Reply With Quote
  #2  
Old 03-24-2017, 06:08 AM
agradinc agradinc is offline
Mirth Newb
 
Join Date: Dec 2015
Posts: 14
agradinc is on a distinguished road
Default

Try
Code:
importpackage(org.apache.commons.lang3.StringUtils)
It's a Rhino function. I've found this to be helpful when trying to use Java in mirth.
Reply With Quote
  #3  
Old 03-24-2017, 06:15 AM
agradinc agradinc is offline
Mirth Newb
 
Join Date: Dec 2015
Posts: 14
agradinc is on a distinguished road
Default

I think you can also use a variable as a shortcut for the full package name. i.e.
Code:
var su = org.apache.commons.lang3.StringUtils;
var defaultString = su.defaultString("hi");

Last edited by agradinc; 03-24-2017 at 07:03 AM.
Reply With Quote
  #4  
Old 03-24-2017, 09:52 AM
ryadical ryadical is offline
OBX.1 Kenobi
 
Join Date: Aug 2016
Posts: 33
ryadical is on a distinguished road
Default

Your first method failed with the below error message but the second one worked perfectly. Thank you for the assistance. I am reading through the link you provided now.

DETAILS: ReferenceError: "importpackage" is not defined.
Reply With Quote
  #5  
Old 03-24-2017, 09:54 AM
narupley's Avatar
narupley narupley is online now
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,119
narupley is on a distinguished road
Default

Quote:
Originally Posted by ryadical View Post
Your first method failed with the below error message but the second one worked perfectly. Thank you for the assistance. I am reading through the link you provided now.

DETAILS: ReferenceError: "importpackage" is not defined.
The correct method is "importPackage".
__________________
Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

Nicholas Rupley
Work: 949-237-6069
Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.


- How do I foo?
- You just bar.
Reply With Quote
  #6  
Old 03-24-2017, 09:58 AM
ryadical ryadical is offline
OBX.1 Kenobi
 
Join Date: Aug 2016
Posts: 33
ryadical is on a distinguished road
Default

Quote:
Originally Posted by narupley View Post
The correct method is "importPackage".
Thank you, that worked. I was able to get the same results from both of the below lines of code:

importPackage(org.apache.commons.lang3);
var StringUtils = org.apache.commons.lang3.StringUtils;
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 08:20 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Mirth Corporation