How to use custom .JAR Mid server packages?

Rushit Patel2
Tera Guru

Hi all,

i uploaded my custom jar as per this page MID Server - ServiceNow Wiki   but it doesnot say how to use it. can any one help?

The jar is uploaded to the extlib folder using the JAR Files module. When I call the methods in the package using the Javascript Probe, I get the output in the ECC queue as :

TypeError: [JavaPackage org.demo.test] is not a function.

However, when I place the jar in the lib folder and invoke the package call using the Javascript Probe, I get the proper results in the ECC queue.

Can you please help me what needs to be done to make the packages call work for the jar placed in extlib folder ?

12 REPLIES 12

Rushit Patel2
Tera Guru

any help...


reedwowens
Giga Expert

Rushit,



I've done this many times.   The big issue I get is knowing how to invoke the Java methods and classes.   Here are some steps that I've done that work:


1)   I created a JAR file with a class called DoSomething and a public method called doIt in a package com.reed.mid


2) Compile the java code and make a JAR file.


3) Upload JAR via ServiceNow MID Application.   Like you mention.


4) Create a JavascriptProbe.   The script has line like:


       


  var doSomething = new Packages.com.reed.mid.DoSomething();



  var result = doSomething.doIt("My parameters");



If you are planning on being at K16, I'm doing a class on "Having it YOUR WAY with the MID Server!"     I'll be covering this entire topic plus add how to debug in this environment.



If this doesn't help, let me know or attach your JAR file and I'll take a look.



If you change the JAR file, you may want to restart the MID Server.


ofaura
ServiceNow Employee
ServiceNow Employee

Hello Reed,



I now this is a quite old question, but I have following the steps suggested building a "Hello World" sample, but I don't get it running. I have done following:



1)   I created a JAR file with a class called DoSomething and a public method called doIt in a package com.reed.mid



package com.reed.mid;


public class DoSomething {


public DoSomething() {


                          }


          public String doIt() {


                          return ("Hello World");


          }


}



2) Compile the java code and make a JAR file. Here my ant jar task to generate the jar file:


          <target name="jar">


                          <jar destfile="lib/testMid.jar" basedir="bin"/>


          </target>



(You can find attached the testMid.jar file)



3) Upload JAR via ServiceNow MID Application.


01.png


4) Create a JavascriptProbe with following script:



  var jspr = new JavascriptProbe('mac-midserver');


  jspr.setName('testMIDServer'); //Any descriptive name will do


  jspr.setJavascript("var doSomething = new Packages.com.reed.mid.DoSomething(); doSomething.doIt();ms.log('Hello World');");


  jspr.create();



5) Review ECC input message:


02.png


As you can see, there the output tag is empty, so my message from the java class has not been returned. Any idea what am I missing here?



Thanks in advance,


Dave Smith1
ServiceNow Employee
ServiceNow Employee

No expert here, but if your Java class is returning something, surely " doSomething.doIt()" should have something that captures the returned value, eg: "var returnValue = doSomething.doIt()"...?



Something seems to be returned to your Javascript, but you don't have any handler for it.