How to Use Java Bean Datasource with Jasper Server


I've got a Collection of Java objects with getters that I want to use to populate a report in Jasper Server. I've searched and found, but it uses an applicationContext.xml which is different from the one that I've got in JasperServer, and I don't know how to adjust it.

How would I use a Collection in JasperServer?

ycohen's picture
Joined: Oct 15 2012 - 11:41am
Last seen: 3 years 6 months ago

2 Answers:



What you need to do is follow the steps described -

1. First you need to create bean like:


public class PersonBean
private String name = "";
private int age = 0;
public PersonBean(String name, int age)
{ = name;
this.age = age;
public int getAge()
return age;
public String getName()
return name;
2. Then you need to make a class that returns a collection fo example:
public class Factory
public static java.util.Collection generateCollection()
java.util.Vector collection = new java.util.Vector();
collection.add(new PersonBean("Ted", 20) );
collection.add(new PersonBean("Jack", 34) );
collection.add(new PersonBean("Bob", 56) );
collection.add(new PersonBean("Alice",12) );
collection.add(new PersonBean("Robin",22) );
collection.add(new PersonBean("Peter",28) );
return collection;

3. Then you need to compile it and add it as an jar  in the folder structure(C:\Program Files\jasperreports-server-x.x\apache-tomcat\lib.).

4. Then while defining the datasource you need to set the following based on the above snippet and set the values as--


Factory class: Factory
Method to call: generateCollection
Return type: Collection of JavaBean
Then you can test the connection and you are good to go
I hope that above explanation helps your cause.


Ankur Gupta's picture
Joined: Jan 21 2013 - 10:36pm
Last seen: 3 weeks 2 days ago

I have tied this procedure, but I got Connection Failed i JasperSever Data Connection.
I have used Bean Data Source.

kjell1906 - 7 years 3 months ago

I got the same 'Connection failed' error. I created Bean Data source in JasperReports Server, and added following information:
Bean Name: Factory
Bean Method: generateCollection
But I couldn't see 'ReturnType' field. I am using JasperServer 5.5.0.

Would really appreciate nay help.

user4561 - 6 years 9 months ago

Hi folks,

Sorry for the trouble actually there is a step missed, 

after the step 3,

You need to add the Jar file to the classpath also.

you could add in the classpath by, Tools(in the Menu bar) --> select the Options --> Select the tab CLASSPATH  --> Click on Add Jar


One thing more I want to clearify is that you need to put both these bean as well as the static factory function in one single java class and access it in setting up the datasource. So suppose you have the package name as com.sample.jasper and your class containing both the bean as well as the factory function is JasperBeanData so the expression for the 

Bean: com.sample.jasper.JasperBeanData

Factory Class : generateCollection.


Hope that this helps establishing the connection.

Please do reply if more clearifications are required.



Ankur Gupta


Ankur Gupta's picture
Joined: Jan 21 2013 - 10:36pm
Last seen: 3 weeks 2 days ago

Which classpath is this. Is it the classpath of JasperServer? I dodnt find Tools and those options in jasperserver page. Where exactly we should enter that jar.

manojshishodia - 6 years 8 months ago

The classpath is of iReport/Jaspersoft Studio,
If you want to use it in jasper server you need to add the jar as the resource to the report.

Ankur Gupta - 6 years 8 months ago

I have added the jar in resource to the report in jasperserver. Also have created the jrxml in ireport having only two fields i.e name and age. While adding data sources i am getting connection failed. I have deployed jasperserver in jboss. Also addded that jar in lib of jboss. What may be the reason of getting connection failed. Any help is appreciated.
Thanks in advance

manojshishodia - 6 years 8 months ago
show 2 more...

Im also having somewhat the same issues (in 6.2.1), i created a detailed step by step of what i did.

does it need to put the jar file in the <web container>/lib, the add the jar as a report resource? isnt this redundant? and also, i tried this and still the bean is not recognized.

jpmillan - 4 years 5 months ago

hi do you need to add the bean to WEB-INF file in the server and restart server.

Jaya5 - 4 years 1 month ago