I'm trying to attach a call to a Java library into the iReport expression.
I tried this with a very simple library returning a hello world string.
package utils;
public class Hello {
public static String hello()
{
return "Hello";
}
}
Within iReport, i want to use this API. I compiled the above library into a jar file. Added the location in Tools -> Options -> Classpath.
then tried the following:
- Editing the expression in a a text field
new utils.Hello().hello()
- Creating a new field and setting its type to
utils.Hello
. Then using thefield.hello()
in the expression
In both cases, it complains that it cannot resolve hello. However its in the classpath. I've also tried to right click on the report root and add utils.Hello/utils
to the Java import directive. Neither of which seemed to pick up the class.
Any advice is greatly appreciated.
Best Answer
Your right expression might be like this:
The working sample:
You can also add import instruction to the report. In this case the expression will be:
The working sample:
Note: For both samples the jar file (with utils.Hello class) must be in classpath.
More info about using srciptlets you can find here.