B4J Library jJasperReports Library

Hi. I want to share this jJasperReports library with the community.
It needs several libraries to work. I provided a link: download
---More libraries needed (missing from the first link): download
You also need to download databases jdbc drivers: sql jdts, mysql and oracle
New Link (All jar files are included in this link): Download
All jars need to be placed in Additional Libraries folder.
In the B4J project you need to add a jar file: #AdditionalJar: itext-2.1.7.js1
Library files and a small example is provided.
Please feel free to test the library.
Note: for some reason when using SubReports, the compiled (.jasper) files need to be in the same level as the app jar file. XML Reports (.jrxml) can be in any other folder different from the app jar file. (e.g. if report.jrxml is in File.DirApp & "/reports" then all compiled (.jasper) subreports need to be in File.DirApp. In the example provided .jrxml and .jasper are in the same level as jaspertest.jar.

v1.00 - Release
v1.10 - SQLite support added. MySQL useSSL variable added.
v1.12 - Changed the way the JasperViewer works. Now you can set the form to full screen, use the default size and location or set a specific size and location.
v1.13 - Added method PrintDirectlyToPrinter.
v1.20 - Access support added via uCanAccess jdbc driver. Note: When creating reports in Jaspersoft Studio you need to add all jar files that ucanaccess needs. The metadata won't work but you can create a query and it will work.
v1.22 - Added functions to export report to XLS and XLSX. Note: need 2 more jar files: download. Copy them into Additional Libraries folder.
v1.24 - Added function Print3 to be able to show reports without a Data Source.

------------------------------------------

NEW VERSION 2.00
Special thanks to Num3 for testing this library and helping me getting it done.

Instructions:
1. Libraries needed: Donwload
2. Place all jars in Additional Libraries folder
3. Specify in B4J project with #AdditionalJar: the database that is going to be used. (e.g. #AdditionalJar: mysql-connector-java-5.1.49-bin)
a. If using ucanaccess-5.1.0 database please add these in addition to #AdditionalJar: ucanaccess-5.0.1:
- #AdditionalJar: commons-lang3-3.8.1
- #AdditionalJar: commons-logging-1.2
- #AdditionalJar: hsqldb-2.5.0
- #AdditionalJar: jackcess-3.0.1

v2.00 - Same functionality as v1.24 but based on jasperreports-6.17.0. Previous v1.24 was based on jasperreports-6.7.1.
 

Attachments

  • mainform.png
    mainform.png
    8.1 KB · Views: 923
  • jrxml_exported_to_pdf.png
    jrxml_exported_to_pdf.png
    53.9 KB · Views: 921
  • jrxml_subreports.png
    jrxml_subreports.png
    53.6 KB · Views: 1,004
  • jrxml_single_report.png
    jrxml_single_report.png
    16.7 KB · Views: 915
  • jJasperReports.zip
    10.2 KB · Views: 433
  • sqlite_report.png
    sqlite_report.png
    35.1 KB · Views: 787
  • jaspertest.zip
    2.8 KB · Views: 506
  • jJasperReports - 1.24.zip
    17.4 KB · Views: 203
  • jJasperReports - 2.00.zip
    17.6 KB · Views: 78
Last edited:

cjpryor

Member
Licensed User
Very good aproach!!
Thank you for all of your work with this. I really appreciate it. BTW, I should clarify that I call the compiled main report from code as well. I am not compiling any of the reports from code. Thanks again!!
 

cjpryor

Member
Licensed User
There may be other ways but I would build a report based on the underlying database with parameters to use in the SQL that retrieves the content for the report. You can then pass the necessary values of the parameters in from B4J when you call the report.

BTW, I think of the .jrxml file as the report specification and the .jasper file as the compiled report for deployment.
 

behnam_tr

Active Member
Licensed User
There may be other ways but I would build a report based on the underlying database with parameters to use in the SQL that retrieves the content for the report. You can then pass the necessary values of the parameters in from B4J when you call the report.

BTW, I think of the .jrxml file as the report specification and the .jasper file as the compiled report for deployment.

thanks
but i want print my data without using sql
i can send some data like date,title ,... with parameters
but i have many data maybe 100rows or more and I cant use 100 parameter!!
i want to make a list in b4j and send to jasper
any other way ??
 

cjpryor

Member
Licensed User
The parameters I was referring to would become part of a query that would determine what rows are returned from the database. So, in my case, I would have collectionID and itemID as paramaters to bring back only the collections and/or items that I want to include in a report. So, I can bring back 100 rows (or more, or less) with only two paramaters.

For example:

B4X:
    Private Const GET_TAB_TEXT_VALUES_BASE_SQL As String = $"SELECT
    TABID, ITEMID, TEXT1, TEXT2, TEXT3, TEXT4, TEXT5, TEXT6, TEXT7, TEXT8, TEXT9, TEXT10, TEXT11, TEXT12, TEXT13, TEXT14, TEXT15, TEXT16,
    TEXT17, TEXT18, TEXT19, TEXT20, TEXT21, TEXT22, TEXT23, TEXT24, TEXT25, TEXT26, TEXT27, TEXT28, TEXT29, TEXT30, TEXT31, TEXT32
    FROM TABFIELDVALUES"$

...

            sqlString = GET_TAB_TEXT_VALUES_BASE_SQL & " WHERE COLLECTIONID = " & args.Get(1) & " AND ITEMID = " & args.Get(2) & " AND TABID = " & args.Get(3)


Here is something similar, but obviously not exactly the same, from one of my reports:

SQL:
SELECT

     b.COLLECTIONNAME AS ITEMID_COLLECTIONTYPENAME,

     c.DATE1,

       a.tabid,

       c.tabid,

     a.TEXT2 AS ITEMID_TEXT2,

     a.TEXT3 AS ITEMID_TEXT3,

     a.TEXT4 AS ITEMID_TEXT4,

     a.TEXT5 AS ITEMID_TEXT5,

     a.TEXT6 AS ITEMID_TEXT6,

     a.TEXT7 AS ITEMID_TEXT7,

     a.TEXT8 AS ITEMID_TEXT8,

     a.TEXT9 AS ITEMID_TEXT9,

     a.TEXT10 AS ITEMID_TEXT10,

     a.TEXT11 AS ITEMID_TEXT11,

     a.TEXT12 AS ITEMID_TEXT12,

     a.TEXT13 AS ITEMID_TEXT13,

     a.TEXT14 AS ITEMID_TEXT14,

     a.TEXT15 AS ITEMID_TEXT15,

     a.TEXT16 AS ITEMID_TEXT16

FROM

TABFIELDVALUES a, COLLECTIONTEMPLATES b

LEFT JOIN TABFIELDVALUES c

on (a.ITEMID = c.ITEMID AND c.TABID = 5)

WHERE

a.COLLECTIONID = b.COLLECTIONID

AND a.TABID = $P{tabId}

AND b.COLLECTIONID =  $P{collectionId}

AND (c.Date1 is null OR c.Date1='')

    AND (a."TEXT15" is null OR a."TEXT15" not like '%o')

    AND (a."TEXT16" is null OR a."TEXT16" not like '%o')


Since you are apparently not using a database to populate your tableview, I guess I do not know enough about your requirements to suggest a solution.
 
Last edited:

cjpryor

Member
Licensed User
I tried to search the web to see if I could find a way to send data directly to a .jrxml file as you requested but cannot seem to find that approach being supported. Of course I could have missed it by not using the proper query or not scrolling through search results far enough. However, there are many connectors available for Jaspersoft (see attached screen capture). Perhaps one of them will work for you?

jasperDataConnectors.jpg
 

cjpryor

Member
Licensed User
Back to a question from earlier in this thread that I could not find the answer to. I am trying to use Jaspersoft "font extensions" but cannot get them to work outside of debug mode in B4J. If I switch to release I get the following error.

Open Report, error = [(JRFontNotFoundException) net.sf.jasperreports.engine.util.JRFontNotFoundException: Font "DejaVu Sans" is not available to the JVM. See the Javadoc for more details.]

It seems the key is to add the jar file containing the fonts to the classpath of the application. As simple as this sounds I cannot seem to figure it out with B4J. I have done the following:
  1. Added the jasperreports-fonts-6.17.0 file to B4X\additionallibraries\B4X
  2. Added #AdditionalJar: jasperreports-fonts-6.17.0 to the project
So, what am I missing?

Here is the relevant instruction from http://jasperreports.sourceforge.net/sample.reference/fonts/

"Once you have the TTF files, the jasperreports_extension.properties and fonts.xml files, you can pack them together in a JAR file, and then put the JAR in your application's classpath, in order to make the new fonts available to your reports, wherever the application might run. "

Thanks,

Clay
 

Juan Marrero

Active Member
Licensed User
Back to a question from earlier in this thread that I could not find the answer to. I am trying to use Jaspersoft "font extensions" but cannot get them to work outside of debug mode in B4J. If I switch to release I get the following error.



It seems the key is to add the jar file containing the fonts to the classpath of the application. As simple as this sounds I cannot seem to figure it out with B4J. I have done the following:
  1. Added the jasperreports-fonts-6.17.0 file to B4X\additionallibraries\B4X
  2. Added #AdditionalJar: jasperreports-fonts-6.17.0 to the project
So, what am I missing?

Here is the relevant instruction from http://jasperreports.sourceforge.net/sample.reference/fonts/

"Once you have the TTF files, the jasperreports_extension.properties and fonts.xml files, you can pack them together in a JAR file, and then put the JAR in your application's classpath, in order to make the new fonts available to your reports, wherever the application might run. "

Thanks,

Clay
That jar file is already added in the wrapper library. Will have to make some tests.
 

cjpryor

Member
Licensed User
@Juan Marrero I just experienced Another Linux issue ... it seems to be limited to Linux only. I will continue to research this but thought I would let you know since you are looking into the font issue. Thanks !!!!

Background:

I am using Ubuntu 20.04.2 LTS with OpenJDK RunTime Environment (build14.0.1+7). I have the same Open JDK on all my development computers.

For now, as a workaround for the font extensions issue, I went ahead and changed the font in the reports to Arial and installed the Microsoft fonts which include Arial on my linux machine. The reports open when running it from b4J using B4J Bridge (in debug and deployed modes). I do see the following warning when running on Linux (and Linux only) from B4J using B4J Bridge in both debug and deploy modes:

B4X:
(java:4118): Gdk-WARNING **: 17:24:17.775: XSetErrorHandler() called with a GDK error trap pushed. Don't do that.

I do not see the above warning when running in my native windows environment or on my Mac.

As an alternative, I wonder if I should just write a native Java Program for the reports. I should be able to spin it off from B4J whenever somebody wants to run reports.

Show Stopper:

Once I build my application on my linux computer using B4J Bridge with B4JPackager11, I get the following error (including a partial stack trace for reference) when I try to open a report:

B4X:
reportspage$ResumableSub_Button_Open_Report_Click.resume (java line: -1)
java.lang.IllegalAccessError: superclass access check failed: class Collections_1627678471394_43471 (in unnamed module @0x19757ea) cannot access class net.sf.jasperreports.engine.fill.JREvaluator (in module b4j) because module b4j does not export net.sf.jasperreports.engine.fill to unnamed module @0x19757ea
    at java.base/java.lang.ClassLoader.defineClass1(Native Method)
    at java.base/java.lang.ClassLoader.defineClass(Unknown Source)
    at b4j/net.sf.jasperreports.engine.util.JRClassLoader.loadClass(Unknown Source)
    at b4j/net.sf.jasperreports.engine.util.JRClassLoader.loadClassFromBytes(Unknown Source)
    at b4j/net.sf.jasperreports.engine.design.JRAbstractJavaCompiler.loadClass(Unknown Source)
    at b4j/net.sf.jasperreports.engine.design.JRAbstractJavaCompiler.loadEvaluator(Unknown Source)
    at b4j/net.sf.jasperreports.engine.design.JRAbstractCompiler.createEvaluator(Unknown Source)
    at b4j/net.sf.jasperreports.engine.design.JRAbstractCompiler.loadEvaluator(Unknown Source)
    at b4j/net.sf.jasperreports.engine.JasperCompileManager.getEvaluator(Unknown Source)
    at b4j/net.sf.jasperreports.engine.fill.JRFillDataset.createCalculator(Unknown Source)
    at b4j/net.sf.jasperreports.engine.fill.BaseReportFiller.<init>(Unknown Source)
    at b4j/net.sf.jasperreports.engine.fill.JRBaseFiller.<init>(Unknown Source)
    at b4j/net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(Unknown Source)
    at b4j/net.sf.jasperreports.engine.fill.JRFiller.createBandReportFiller(Unknown Source)
    at b4j/net.sf.jasperreports.engine.fill.JRFiller.createReportFiller(Unknown Source)
    at b4j/net.sf.jasperreports.engine.fill.JRFiller.fill(Unknown Source)
    at b4j/net.sf.jasperreports.engine.fill.JRFiller.fill(Unknown Source)
    at b4j/net.sf.jasperreports.engine.JasperFillManager.fill(Unknown Source)
    at b4j/net.sf.jasperreports.engine.JasperFillManager.fillReport(Unknown Source)
    at b4j/com.prusb.jasperrep2.JasperReports.Print(Unknown Source)
 

Juan Marrero

Active Member
Licensed User
thanks
but i want print my data without using sql
i can send some data like date,title ,... with parameters
but i have many data maybe 100rows or more and I cant use 100 parameter!!
i want to make a list in b4j and send to jasper
any other way ??
As for sending a tableview's data to jasperreports. JasperReports uses an table object that I thought would be the solution, but it also asks for a datasource when configuring it. There is an option to use it without datasource but I can't find a way to send the rows from the tableview to that table object. Maybe there is a way but I haven't found it.
My recommendation is either use sqlite to store the rows or use an xml file. I you use an xml file as datasource, you need to be consistent in the number of columns. First you need to create the xml file by code without calling the report. After the xml is created, create a new report and connect it to that xml file. Add the fields as usual and test it. Then call the report from code after recreating the same xml file and check if the report works.
 

Juan Marrero

Active Member
Licensed User
@Juan Marrero I just experienced Another Linux issue ... it seems to be limited to Linux only. I will continue to research this but thought I would let you know since you are looking into the font issue. Thanks !!!!

Background:

I am using Ubuntu 20.04.2 LTS with OpenJDK RunTime Environment (build14.0.1+7). I have the same Open JDK on all my development computers.

For now, as a workaround for the font extensions issue, I went ahead and changed the font in the reports to Arial and installed the Microsoft fonts which include Arial on my linux machine. The reports open when running it from b4J using B4J Bridge (in debug and deployed modes). I do see the following warning when running on Linux (and Linux only) from B4J using B4J Bridge in both debug and deploy modes:

B4X:
(java:4118): Gdk-WARNING **: 17:24:17.775: XSetErrorHandler() called with a GDK error trap pushed. Don't do that.

I do not see the above warning when running in my native windows environment or on my Mac.

As an alternative, I wonder if I should just write a native Java Program for the reports. I should be able to spin it off from B4J whenever somebody wants to run reports.

Show Stopper:

Once I build my application on my linux computer using B4J Bridge with B4JPackager11, I get the following error (including a partial stack trace for reference) when I try to open a report:

B4X:
reportspage$ResumableSub_Button_Open_Report_Click.resume (java line: -1)
java.lang.IllegalAccessError: superclass access check failed: class Collections_1627678471394_43471 (in unnamed module @0x19757ea) cannot access class net.sf.jasperreports.engine.fill.JREvaluator (in module b4j) because module b4j does not export net.sf.jasperreports.engine.fill to unnamed module @0x19757ea
    at java.base/java.lang.ClassLoader.defineClass1(Native Method)
    at java.base/java.lang.ClassLoader.defineClass(Unknown Source)
    at b4j/net.sf.jasperreports.engine.util.JRClassLoader.loadClass(Unknown Source)
    at b4j/net.sf.jasperreports.engine.util.JRClassLoader.loadClassFromBytes(Unknown Source)
    at b4j/net.sf.jasperreports.engine.design.JRAbstractJavaCompiler.loadClass(Unknown Source)
    at b4j/net.sf.jasperreports.engine.design.JRAbstractJavaCompiler.loadEvaluator(Unknown Source)
    at b4j/net.sf.jasperreports.engine.design.JRAbstractCompiler.createEvaluator(Unknown Source)
    at b4j/net.sf.jasperreports.engine.design.JRAbstractCompiler.loadEvaluator(Unknown Source)
    at b4j/net.sf.jasperreports.engine.JasperCompileManager.getEvaluator(Unknown Source)
    at b4j/net.sf.jasperreports.engine.fill.JRFillDataset.createCalculator(Unknown Source)
    at b4j/net.sf.jasperreports.engine.fill.BaseReportFiller.<init>(Unknown Source)
    at b4j/net.sf.jasperreports.engine.fill.JRBaseFiller.<init>(Unknown Source)
    at b4j/net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(Unknown Source)
    at b4j/net.sf.jasperreports.engine.fill.JRFiller.createBandReportFiller(Unknown Source)
    at b4j/net.sf.jasperreports.engine.fill.JRFiller.createReportFiller(Unknown Source)
    at b4j/net.sf.jasperreports.engine.fill.JRFiller.fill(Unknown Source)
    at b4j/net.sf.jasperreports.engine.fill.JRFiller.fill(Unknown Source)
    at b4j/net.sf.jasperreports.engine.JasperFillManager.fill(Unknown Source)
    at b4j/net.sf.jasperreports.engine.JasperFillManager.fillReport(Unknown Source)
    at b4j/com.prusb.jasperrep2.JasperReports.Print(Unknown Source)
I did a quick search of the gdk-warning. It seems like there is an incompatibility issue between OpenJDK and GTK3. Will keep digging.

As for the error, the error refers to an import that I haven't added to the project (At least explicitly). I know I can import it, but will take some time to test it.
 

cjpryor

Member
Licensed User
"DejaVu Sans" is one of the default JasperReports fonts included in jasperreports-fonts-6.17.0.jar. That is why I chose it. Please see http://jasperreports.sourceforge.net/sample.reference/fonts/ (also referenced earlier in this thread).

I am making some progress on an external java application which will be called from B4X and then will open the selected reports which I am going to deploy as a "fat" jar to include all required jars including the Fonts. I am working on the "fat" deployment part now. I need Eclipse for that (At least that is how I used to deploy "fat" jars so I know how to do it with Eclipse) but their site has been down all day yesterday and still not fully operational today.

Thanks.
 

Juan Marrero

Active Member
Licensed User
"DejaVu Sans" is one of the default JasperReports fonts included in jasperreports-fonts-6.17.0.jar. That is why I chose it. Please see http://jasperreports.sourceforge.net/sample.reference/fonts/ (also referenced earlier in this thread).

I am making some progress on an external java application which will be called from B4X and then will open the selected reports which I am going to deploy as a "fat" jar to include all required jars including the Fonts. I am working on the "fat" deployment part now. I need Eclipse for that (At least that is how I used to deploy "fat" jars so I know how to do it with Eclipse) but their site has been down all day yesterday and still not fully operational today.

Thanks.
Can you post an example on how are you using DejaVu Sans font in B4J? I honestly integrated that jar in previous version 1 of this library for another person. He was using it so I just integrated the new version in version 2 of this library. Haven't tried it myself.
Also an example of the error opening the report.
 

cjpryor

Member
Licensed User
Unfortunately I have moved along in my current development to use my custom jar so it is very hard for me to revert right now to rewrite my code again to test for you. I know you are busy but if you would have gotten back to me sooner I would have been happy to revisit this for you then. Unfortunately I moved on to a new approach.

If I fail in my current external java wrapper effort I will revert to jJasperReports. My approach is working in Debug mode but it fails in Release mode (sound familiar?). The ability to call a custom jar file will be essential to other features I plan to develop so I really need to make this work.

I can tell you this, if you look at the .classpath for your jJasperReports2.jar you will find the fonts ARE included. However, they did not work when I created a report to use them in Release mode.

I hope you understand.

:)

Thanks!

Clay
 
Last edited:

Juan Marrero

Active Member
Licensed User
Unfortunately I have moved along in my current development to use my custom jar so it is very hard for me to revert right now to rewrite my code again to test for you. I know you are busy but if you would have gotten back to me sooner I would have been happy to revisit this for you then. Unfortunately I moved on to a new approach.

If I fail in my current external java wrapper effort I will revert to jJasperReports. My approach is working in Debug mode but it fails in Release mode (sound familiar?). The ability to call a custom jar file will be essential to other features I plan to develop so I really need to make this work.

I can tell you this, if you look at the .classpath for your jJasperReports2.jar you will find the fonts ARE included. However, they did not work when I created a report to use them in Release mode.

I hope you understand.

:)

Thanks!

Clay
Got it.
 

cjpryor

Member
Licensed User
okay, I am stuck in my other approach and submitted a request for help in another thread so I will refactor my B4J application to use your jJasperReort library now - just have to find it in my code repository.

:)

Thanks
 
Top