venujasper Posted March 30, 2009 Share Posted March 30, 2009 Hi , I am using ireport tool in web application to generate reports.There is a requirement to call java function from ireport tool.Is there any way to call java function from ireport. Any idea? Thanks,Kitti Link to comment Share on other sites More sharing options...
svenn Posted March 30, 2009 Share Posted March 30, 2009 First iReports is the report designer. Jasper Report is the reporting engine.When you say Java function what do you mean? Do you mean your own custom Java Class? What are you doing in this Class? Link to comment Share on other sites More sharing options...
venujasper Posted March 31, 2009 Author Share Posted March 31, 2009 Hi, Yes I mean custom java class,I need this to encode and decode the fields.i need to pass the fields to the custom java class and get the decoded format of fields.Can i do this using ireport tool. Regards, Kitti Link to comment Share on other sites More sharing options...
djsiders Posted April 1, 2009 Share Posted April 1, 2009 Yes, build you java class, put it in a jar, and then ref the object in your jasper wherever yo want to use it's methods.example:Create class Decoder that just converts lower to upper casepackage dummy.test;public class Decoder { public String decode(String input) { return input == null ? "" : input.toUpperCase(); } }Create a jar containing that class, and place on classpath.Create a blank report an put one text field on the report with the following expression as it's value.new dummy.test.Decoder().decode("this was all lower case")The report will show the converted text "THIS WAS ALL LOWER CASE"Couldn't get this to work with a static method for some reason, but didn't try real hard.You can also create a parameter in your report of type dummy.test.Decoder with the default value = new dummy.test.Decoder()Then whenever you want to use the method in a text box, etc. just use expression $P{PARM_NAME}.decode(strValue)This allows you to new the Dummy class once and use in multiple places in your report (or even pass as a param to a subreport) Link to comment Share on other sites More sharing options...
Giulio Toffoli Posted April 1, 2009 Share Posted April 1, 2009 You should use static methods to avoid to instance a new class all the times you need to call your function.Be sure you class is in the classpath. Link to comment Share on other sites More sharing options...
venujasper Posted April 2, 2009 Author Share Posted April 2, 2009 Thank you very much.This is very usefull. Thanks & Regards, Kitti Link to comment Share on other sites More sharing options...
awadhai Posted September 1, 2010 Share Posted September 1, 2010 I am trying to create report using ireport(3.5.1) & i want to use Custom class. where my custom class reading file & returning a string like package org.test.com;public class ReadUrlFile { public String getInputUrls() { //reading file.... return urls;}for this i have created java class, made a jar, and then i have added text fied in report & refer the Class in jasper to use it's methods.like new org.test.com.ReadUrlFile().getInputUrls()i also tried like (new org.test.com.ReadUrlFile()).getInputUrls()I have added jar in ireprt classpath from : Tools > option > classpath.when i click on preview i am getting ClassNotFoundException Anyone help me to come out.what i have missing Thanks,awadhai Link to comment Share on other sites More sharing options...
iamlegend108 Posted April 18, 2012 Share Posted April 18, 2012 yes we can call java methods from jasper reports. Just Follow the following steps Step1:create a java class with a static method which return something i.e either String or Integer.. Step2:Create a jar file by command jar - cvf file.jar packagename Step3:set it as class path as Tools > Options > ClassPath > Add Jar > Ok Step4: Create a Static field. Edit its Expression by EditExpression to "new packagename.classname().methodname(parameter) "Step5:Place this static field wherever you want Link to comment Share on other sites More sharing options...
cavagnaro.jc Posted July 8, 2013 Share Posted July 8, 2013 Hi, Is this the same as an scriplet or no need to be like that? I've been trying for days to do this but no luck...searched for info all these days and couldn't find a good sample with code. If any of you have a guide please would be awesome to share it. Thanks Link to comment Share on other sites More sharing options...
therrick_1 Posted August 21, 2015 Share Posted August 21, 2015 I get compile error "GetFileLoc.getLoc cannot be resolved to a type" and "Errors were encountered when compiling report expressions class file". Java is this:package testJSS;import java.io.File;public class GetFileLoc {public static String getLoc(){File currentDir = new File("").getAbsoluteFile();String loc = currentDir.toString();return loc;} public static void main(String[] args){// String loc = GetFileLoc.getLoc();// System.out.println(loc);}}// close classText Field expression in Report is this: (new GetFileLoc.getLoc())Went into Project > Properties > Java Build Path > Libraries and added the External Jar. Any ideas? Link to comment Share on other sites More sharing options...
kossonou_landry Posted July 22, 2016 Share Posted July 22, 2016 Try to specify the full name of the component (package.componentname.method).It looks like you don't provide the package name.Set the expression as the following:new testJSS.GetFileLoc.getLoc() Link to comment Share on other sites More sharing options...
g.den.breejen Posted February 26, 2017 Share Posted February 26, 2017 For a customer we need to decrypt stored data to show on the Jaspersoft report using a JAVA function that performs the decryption.The report language is set to "groovy", used version Jaspersoft report server 6.2. It works on older versions like 4.7.1 as well, as done earlier in the project.The utils.java.helpers.jar is put in both the classpath of Jaspersoft Studio (or iReport when JS 5.5 or older is used) and in the lib folder of the deployed WAR file in Tomcat.To call a JAVA function, create a field and add an expression like the exxample below:new GroovyClassLoader().parseClass(''' def static decryptCPR(String cpr, String meteringPoint, String envKey) { String decryptedKey = utils.java.helpers.CryptoLib.decryptCPR(cpr, meteringPoint, envKey); return decryptedKey; }''').decryptCPR($F{FIRST_CONSUMER_CPR}, $F{MPO_METERING_POINT_ID}, $P{P_ENV_KEY} ) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now