Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom Jar file on Jasper Server

I wrote some Java class, created jar file. I want to add it to JasperReports Server. When I determine the path to my jar file, using Tools -> Preferences -> Classpath menu in my iReport, it works correctly. But it doesn't work, when I take access to JR Server from another host.

What I must to do, to make this jar file available on this JR Server, from anywhere?

like image 657
yura Avatar asked Oct 09 '12 12:10

yura


2 Answers

Option 1 - If you want to use your Jar in a several reports.

You should "Add Jar" (as it called in iReport repository manager) to some folder in the Jasper Server folder tree. Then "Add reference" to this resource in Resources section of you specific report.

Option2 - You need a jar in a specifc report.

Use "Add Jar" option in a resources section of specific report.

Worked perfectly on JasperServer 4.7

like image 87
Alex Chevelev Avatar answered Oct 09 '22 20:10

Alex Chevelev


Add the jar as a resource of the report (if it's one time use) or add it to some path in Jasper Report Server and add a reference to it as Alex suggested.

I'd suggest you to create some folders in Jasper Server (via web interface or iReport) and put all commonly used filed there (be sure to manage correctly the permissions ROLE_USER should have access to the file but you can remove it from the folder so it's not listed).

Then use references on the reports that need those. For example, I use it for the report logo and some helper Java classes.

Edit as @NormTatlock asked more details on how to do it:

  1. Create your Java package my.sample.package for example:

    public class MyClass extends JRDefaultScriptlet ...

  2. Compile it and upload the jar as a resource using its full name (e.g. my.sample.package.jar) or upload it to another folder and create a reference to it in the resources folder of the report.

  3. Edit the report and set the Scriptlet Class property to:

    my.sample.package.MyClass

  4. Or set the property in the XML tag jasperreports (the root tag) as:

    scriptletClass="my.sample.package.MyClass"

  5. Use the scriptlet in your report like this:

    $P{REPORT_SCRIPTLET}.myMethod(myParam1, myParam2)

Mind the return type of the methods and so on.

Hope it helps. Have fun!

like image 34
marram Avatar answered Oct 09 '22 19:10

marram