There is a new comment on your post!
If this comment helps you, consider marking it as best reply.
AC

Hello,



In this article I will share my findings on calling Java code from ARIS reports. It all started with this article http://www.ariscommunity.com/users/kylekatarn/2010-10-31-calling-static-java-methods-report where I described the problem of calling Java's Runtime.getRuntime() method inside an ARIS report. A brief solution was also presented. As I learned more about the topic I found that the presented solution tackles the more generic issue of "Calling java code from ARIS".



Here is a small tutorial you can follow in order to access your java classes in a report. The example I'm presenting here will display Java Runtime memory information.

 

1. Open eclipse and create a new java project. I'm using ARIS 7.0.2 therefore both my code and final jar must target Java 1.5

 

2. Create one or more java classes. In our example I will need only one class to store the code I can't access directly in a report - java runtime information memory settings.

 

3. In this case, the code is as simple as this:

Eclipse should automatically compile the code into .class files.

 

4. Export compiled code into a jar file. Remember to deploy jar into the server's lib directory.

 

5. Restart ARIS server. After that, our custom jar will be available in reports.

 

6. Create the report to test it out. We will be just displaying a message box with runtime memory information, so in this case the report context doesn't matter at all and there is no output (xls, txt, pdf, ...)

I hope the image above really enlighten you. The java class we want to use is inside the 'aris.hacks' package. Therefore, we must "import" that into the report's scope. Remeber to prefix the package name with 'Packages', that's the way of telling Rhino (the underlying javascript engine) it's a java package.

Since our method (getRuntime) is static we access it directly through the class (JavaWrapper).

 

7. Run the code and be amazed

 

I believe all classes in your jar will be available in all reports, since we have placed  the JAR in the server’s lib directory. The only thing you have to do in order to use those classes is to import the package and set up the scope (‘with’ statement).

However, the ‘with’ statement isn’t really necessary, you could write:

    var rt = imp.JavaWrapper.getRuntime();

And the code would work without the ‘with’ block.

But I like to have the with block  so I always know the import scope borders. And it saves us from repeating code (imp.xxx).

And that's it. You should now be able to call *anything java* from an aris report, which gives you lot's of extra freedom while developing scripts. This should work for macros also, just deploy the jar in the client's lib folder, the logic is the same.



Attached to this post you will find the following artifacts, zipped:

  • "JavaWrapper.jar" - ready to deploy JAR with the example's code)
  • "JavaWrapper (EclipseProject).zip" - eclipse project with source code
  • "Java Runtime Memory Information.arx" - ARIS report used to call java code

 

All the information presented above targets ARIS 7.0.2 and it's 100% non-official. This means it's just a collection of things I discovered here and there, far from any kind of documentation. From what I could find, official documentation says nothing about this matters. My tools were trial-and-error, ARIS Community, the Interweb and some bits of magic powder.. I'm also not an expert in javascript, far from that.



As a final remark, I have to say I'm also aware of this article http://www.ariscommunity.com/users/eva-klein/2010-11-15-difference-between-aris-report-and-macro where Eva Klein says that a jar can be imported like a *.js file via the 'Edit > Imported Scripts' menu. For some reason (ARIS version?), that didn't work for me. Therefore what I've shared here works but may be outdated. However, I hope it helps someone in some way.



If I have the time I may post some other interesting bits on scripting.

~have fun

File attachments
by Han Boogaardt
Posted on Thu, 03/03/2011 - 16:42

Excellent article, thanks!



I have one note: the JAR did not work if placed in the server\lib folder.



Since I work with other JAR applets which are placed in the server\jre\lib\ext folder, I placed it there and that worked.



If you have other interesting bits on scripting which haven't been published yet, please post them here.



Cheers.

0
by Konstantin Seleznev
Posted on Thu, 05/03/2012 - 21:05

Hello. There is the problem:

Access to Java class "java.lang.Runtime" is prohibited.

What can I do now?

0
by Konstantin Seleznev
Posted on Sun, 05/06/2012 - 11:18

Hi Freddy,

Do you mean following code?

var rtclass = java.lang.Class.forName("java.lang.Runtime");
var rtfunc = rtclass.getMethod("getRuntime");
var rt = rtfunc.invoke(null);

So, this code does not work too with the same problem:

Access to Java class "java.lang.Runtime" is prohibited.

0

Featured achievement

Rookie
Say hello to the ARIS Community! Personalize your community experience by following forums or tags, liking a post or uploading a profile picture.
Recent Unlocks

Leaderboard

|
icon-arrow-down icon-arrow-cerulean-left icon-arrow-cerulean-right icon-arrow-down icon-arrow-left icon-arrow-right icon-arrow icon-back icon-close icon-comments icon-correct-answer icon-tick icon-download icon-facebook icon-flag icon-google-plus icon-hamburger icon-in icon-info icon-instagram icon-login-true icon-login icon-mail-notification icon-mail icon-mortarboard icon-newsletter icon-notification icon-pinterest icon-plus icon-rss icon-search icon-share icon-shield icon-snapchat icon-star icon-tutorials icon-twitter icon-universities icon-videos icon-views icon-whatsapp icon-xing icon-youtube icon-jobs icon-heart icon-heart2 aris-express bpm-glossary help-intro help-design Process_Mining_Icon help-publishing help-administration help-dashboarding help-archive help-risk icon-knowledge icon-question icon-events icon-message icon-more icon-pencil forum-icon icon-lock