Hi,
Can anyone please tell me a way to execute the jasper report through java , as well as please tell me which jars are needed to be used?
Also please tell hoe to pass prameters and as well as how to retrieve which parameters are required through java program ,in order to run jasper report.
Thanks,
Ankur
4 Answers:
Hi all ,
I have found a solution to the query on my own, thanks augarte for the explanation regarding the implementation in java that helped,but the real problem was that retrieving the parameters from the jrxml .It is possible to do so.
I found a way for that by parsing the xml and then extracting the tags with parameter and retrieving the attribute name and class keeping in mind the check attribut isForPrompting is blank or not present for the parameters , In this way I got the Hashmap of all the parameters with their types and I put that in the parameterMap and hence fulfilling the parameters in the jrxml dynamically .Solves the purpose for me.
The jars need to be included are-
1.commons-beanutils-x.x.x.jar
2.commons-collections-x.x.x.jar
3.commons-digester-x.x.jar
4.commons-logging-x.x.jar
5.groovy-all-x.x.x.jar
6.iText-x.x.x.jar
7.jasperreports-x.x.x.jar
8.poi-x.x.jar(for excel export)
9.jfreechart-x.x.x.jar
Hope that this is helpful
Regards,
Ankur
Hi,
The code depends on the datasource you want to use for generating the report, this one is an example that shows how to create a pdf file having a xml datasource and a jrxml file:
In thas case you need to get the connection to the database first. This link can help you: http://www.roseindia.net/tutorial/java/jdbc/jdbcdrivermanager.html
Then, the code should be very similar to the one I have posted. The only modification is the call to fillReport function:
JasperPrint Prn = JasperFillManager.fillReport (Rep, new HashMap (), Con);
As you can see the only modification is in the last parameter "Con" (java.sql.Conneciton type), which is the connection to your database, and you can get it in the link I have put above.
Hope this helps.
Regards
Have followed the steps but I am getting a exception:
Exception in thread "main" java.lang.NoClassDefFoundError: org/codehaus/groovy/control/CompilationFailedException
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
at net.sf.jasperreports.engine.util.JRClassLoader.loadClassForRealName(JRClassLoader.java:157)
at net.sf.jasperreports.engine.util.JRClassLoader.loadClassForName(JRClassLoader.java:115)
at net.sf.jasperreports.engine.JasperCompileManager.getCompiler(JasperCompileManager.java:730)
at net.sf.jasperreports.engine.JasperCompileManager.compile(JasperCompileManager.java:240)
at net.sf.jasperreports.engine.JasperCompileManager.compile(JasperCompileManager.java:173)
at net.sf.jasperreports.engine.JasperCompileManager.compileReport(JasperCompileManager.java:448)
at Report.main(Report.java:43)
Caused by: java.lang.ClassNotFoundException: org.codehaus.groovy.control.CompilationFailedException
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:303)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:316)
Can you tell where is the problem
Regards,
Ankur
Hi,
In the report Properties there is an option "Language" (check the attachment). I think your poblem is that you have selected "Groovy" instead of Java. Try changing this property and setting it as Java.
This might solve your problem.
Regards
Attachment | Size |
---|---|
![]() | 15.77 KB |
The datasource used is JDBC if you could please tell about that