B4J Question Library Error when deployed but not in B4J Development Environment

cjpryor

Active Member
Licensed User
I wrote an enhancement to my reporting using DynamicJasper. I built a limited java wrapper specific to my purposes and deployed it to B4J as a library using the B4J_LibraryCompiler.exe. I have done this before with Jasper Reports which has been successfully deployed to Windows, Mac, and Linux.

This new wrapper works well within the B4J development environment in both Debug and Release modes. However, when I deploy it as a B4J application run it in Windows - I have not tested other environments - I get the following error. Other than the first line below, which I included for context, this error is coming from the DynamicJasper jar that I wrapped for my library.

net.nmcollector.PrintPageReportWrapper openPrintPageReport JasperPrint finalReport = DynamicJasperHelper.generateJasperPrint(dynamicReport, ...
Nov 11, 2021 9:28:08 AM ar.com.fdvs.dj.core.DynamicJasperHelper generateJasperPrint
INFO: generating JasperPrint
Nov 11, 2021 9:28:08 AM ar.com.fdvs.dj.core.DynamicJasperHelper generateJasperReport
INFO: generating JasperReport (DynamicReport dr, LayoutManager layoutManager, Map generatedParams)
Nov 11, 2021 9:28:08 AM ar.com.fdvs.dj.core.DynamicJasperHelper generateJasperReport
INFO: generating JasperReport with prefix: r
Nov 11, 2021 9:28:08 AM ar.com.fdvs.dj.core.DJJRDesignHelper getNewDesign
INFO: Creating DynamicJasperDesign
Errors were encountered when compiling report expressions class file:
error: no source files

Here is a code snippet of how I am using it withing B4J:

{code}

Private Sub Button_Print_Page_Click

Try

Dim sqlConnectionString As String = File.Combine(File.DirData("nmcollector"),"nmcswDB.sqlite")

Dim printPageReportWrapper As PrintPageReportWrapper

'arg[0] = sqlConnectionString
'arg[1] = Collection ID
'arg[2] = Item ID
'arg[3] = Tab ID
'arg[4] = Report Title

printPageReportWrapper.openPrintPageReport(Array As String(sqlConnectionString, MainPage.selectedCollectionId, MainPage.selectedItemId, MainPage.selectedTab, MainPage.tabLabelsList.Get(MainPage.selectedTab) & ": " & B4XFloatTextFieldItemListValue.text))

Catch

Dim sf As Object = xui.Msgbox2Async(LastException, "Error", "OK", "", "", Null)
Wait For (sf) Msgbox_Result (Result As Int)

End Try

End Sub

{/code}

Here is a screen capture snippet of it's reverence as a B4J Library:

printPageWrapper.png


I am in the process of troubleshooting this myself but any ideas are welcome. Since it does not seem to be anything obvious I am going to look at the Dynamic Jasper source code for hints.

As a side note, I have a similar java wrapper for jasper reports (not Dynamic Jasper) that I was able to build and deploy successfully.

Thanks!
 
Last edited:

cjpryor

Active Member
Licensed User
I'm thinking perhaps I should just deploy my wrapper java program as a jar and call the jar file from B4J.
 
Upvote 0

cjpryor

Active Member
Licensed User
So, I did the external jar and get the exact same results! The standalone jar works just fine, The B4J application works fine in the development environment. However, when I use the built in B4J Packager (Project > Build Standalone Package) to build the app and then immediately it I get the same error with both the external jar as well as the library.

More details about the external jar file can be found here: https://www.b4x.com/android/forum/t...jar-file-to-call-from-b4j.135972/#post-860049

I am continuing the discussion here because this thread has more context.

The stack trace I see when running the jar by itself standalone (with java -jar PrintPageReportWrapperJar.jar) follows.

NOTES:
  • Report works
  • I chose to give the jar file a different name than the lib to avoid conflicts/confusion within B4J.
Jar - net.nmcollector.PrintPageReportWrapperJar openPrintPageReport Step 4. Insert data into table:
Jar - net.nmcollector.PrintPageReportWrapperJar openPrintPageReport PrintPageReport PrintPageReport = reportBuilder.build();
Jar - net.nmcollector.PrintPageReportWrapperJar openPrintPageReport JasperPrint finalReport = DynamicJasperHelper.generateJasperPrint(dynamicReport, ...
Nov 13, 2021 9:16:46 AM ar.com.fdvs.dj.core.DynamicJasperHelper generateJasperPrint
INFO: generating JasperPrint
Nov 13, 2021 9:16:46 AM ar.com.fdvs.dj.core.DynamicJasperHelper generateJasperReport
INFO: generating JasperReport (DynamicReport dr, LayoutManager layoutManager, Map generatedParams)
Nov 13, 2021 9:16:46 AM ar.com.fdvs.dj.core.DynamicJasperHelper generateJasperReport
INFO: generating JasperReport with prefix: r
Nov 13, 2021 9:16:46 AM ar.com.fdvs.dj.core.DJJRDesignHelper getNewDesign
INFO: Creating DynamicJasperDesign
Nov 13, 2021 9:16:46 AM ar.com.fdvs.dj.core.DynamicJasperHelper generateJasperReport
INFO: Done generating JasperReport for design with name: PrintPage Report Name_5556
Jar - net.nmcollector.PrintPageReportWrapperJar openPrintPageReport Step 5. Export final report to a file in desired format:

The stack trace I get when in the B4J development environment is as follows.

NOTES:
  • Report works
  • There is a warning but it seems to appear after the point in which the report crashes in the deployed application. I believe that warning is due to the fact that I do use Jasper Reports in the B4J application for my standard reports which do work when deployed.
Jar - net.nmcollector.PrintPageReportWrapperJar openPrintPageReport Step 4. Insert data into table:
Jar - net.nmcollector.PrintPageReportWrapperJar openPrintPageReport PrintPageReport PrintPageReport = reportBuilder.build();
Jar - net.nmcollector.PrintPageReportWrapperJar openPrintPageReport JasperPrint finalReport = DynamicJasperHelper.generateJasperPrint(dynamicReport, ...
Nov 13, 2021 9:11:32 AM ar.com.fdvs.dj.core.DynamicJasperHelper generateJasperPrint
INFO: generating JasperPrint
Nov 13, 2021 9:11:32 AM ar.com.fdvs.dj.core.DynamicJasperHelper generateJasperReport
INFO: generating JasperReport (DynamicReport dr, LayoutManager layoutManager, Map generatedParams)
Nov 13, 2021 9:11:32 AM ar.com.fdvs.dj.core.DynamicJasperHelper generateJasperReport
INFO: generating JasperReport with prefix: r
Nov 13, 2021 9:11:32 AM ar.com.fdvs.dj.core.DJJRDesignHelper getNewDesign
INFO: Creating DynamicJasperDesign
Nov 13, 2021 9:11:33 AM ar.com.fdvs.dj.core.DynamicJasperHelper generateJasperReport
INFO: Done generating JasperReport for design with name: PrintPage Report Name_3176
Nov 13, 2021 9:11:33 AM net.sf.jasperreports.extensions.DefaultExtensionsRegistry loadRegistries
WARNING: Extension resource jar:file:/C:/data/B4X/additionallibraries/B4X/PrintPageReportWrapperJar.jar!/jasperreports_extension.properties was found to be a duplicate of jar:file:/C:/data/B4X/additionallibraries/B4X/jasperreports-6.17.0.jar!/jasperreports_extension.properties in classloader jdk.internal.loader.ClassLoaders$AppClassLoader@2f7a2457
Jar - net.nmcollector.PrintPageReportWrapperJar openPrintPageReport Step 5. Export final report to a file in desired format:

The stack trace I see with the B4J app using the jar file when deployed is ...

NOTES:
  • Report DOES NOT work
  • The code does not reach the point where the warning occurred in the B4J development environment.
Jar - net.nmcollector.PrintPageReportWrapperJar openPrintPageReport Step 4. Insert data into table:
Jar - net.nmcollector.PrintPageReportWrapperJar openPrintPageReport PrintPageReport PrintPageReport = reportBuilder.build();
Jar - net.nmcollector.PrintPageReportWrapperJar openPrintPageReport JasperPrint finalReport = DynamicJasperHelper.generateJasperPrint(dynamicReport, ...
Nov 13, 2021 9:22:18 AM ar.com.fdvs.dj.core.DynamicJasperHelper generateJasperPrint
INFO: generating JasperPrint
Nov 13, 2021 9:22:18 AM ar.com.fdvs.dj.core.DynamicJasperHelper generateJasperReport
INFO: generating JasperReport (DynamicReport dr, LayoutManager layoutManager, Map generatedParams)
Nov 13, 2021 9:22:18 AM ar.com.fdvs.dj.core.DynamicJasperHelper generateJasperReport
INFO: generating JasperReport with prefix: r
Nov 13, 2021 9:22:18 AM ar.com.fdvs.dj.core.DJJRDesignHelper getNewDesign
INFO: Creating DynamicJasperDesign
Errors were encountered when compiling report expressions class file:
error: no source files

Barring any new ideas from this community, my next steps are as follows:
  • Look into resolving the Warning in the B4J development environment
  • Try an earlier version of Dynamic Jasper (5.3.1 along with the corresponding version of Jasper Reports)
  • NOTE: I have already substituted an older Jasper Reports (6.13.0) with the latest Dynamic Jasper (5.3.2) to eliminate a deprecation warning generated in Dynamic Jasper for the recommended version of Jasper Reports (6.17.0). I was able to eliminate the deprecation warning but still cannot get reports out of the deployed B4J application
As a last resort, which I really do not want to do, I may have to develop a completely standalone java reporting application outside of B4J.

Thanks in advance for any suggestions!
 
Upvote 0

cjpryor

Active Member
Licensed User
An earlier version of Dynamic Jasper (5.3.1) did not help. Also, I noticed the location of the error in the Dynamic Jasper code was dealing with sub-reports so I created a dummy sub report to see if that would help and it did not.

Since I got the same result with the standalone jar, I went back to the library for now. That resolved the Extension resource WARNING noted above.

For now I am going to focus on any B4JPackager options I might have available to me ... since it seems to be related to how the B4J application is packaged ... I assume that since it works fine within the B4J IDE as well as the standalone jar file but both fail when the B4J application is deployed.

Any help/suggestions greatly appreciated. If somebody provides the solution I will reward them with more than just thanks.

:)
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
I do not know Jasper reports and have no need of it myself, otherwise I would try and help. Hopefully someone is using the setup you are having problems with.
 
Upvote 0

cjpryor

Active Member
Licensed User
Based on th fact that they work from within the B4J development environment and a standalone jar but not in the B4J packaged app, I don’t think it is jasper reports as much as the B4J packaging.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Yes, as Jasper reports seems to be compiling, it will need to be able to find the resources it needs, which appears not to be the case in your example. Without trying it, and I am not set up for that, I can't be much more help than that. I would say that if you are storing the jasper working files in the Files folder, I would try copying them to the apps directory (File.DirData(AppName) or preferably set the xui.SetDataFolder(AppName) and use xui.DefaultFolder) so the are definitely accessible
 
Upvote 0

cjpryor

Active Member
Licensed User
Yes, good point … but I don’t know what resource it is looking for … or if that’s even the case. This error is coming from within Jasper Reports which is called by Dynamic Jasper which is called by my java program. :)

I did think of another alternative … I could just write my data out to HTML files and display them in the native browser. They could be printed from the browser. However, Jasper Reports gives the end user more options than an HTML file displayed in a browser.
 
Last edited:
Upvote 0

stevel05

Expert
Licensed User
Longtime User
The files folder is read only at runtime and packed in the jar, so if it's trying to store compiled files in the same location for later use it will fail.

I don't know for sure this is the case, but unless someone that is familiar with it can help, it's probably worth the time to try.
 
Upvote 0

cjpryor

Active Member
Licensed User
The files folder is read only at runtime and packed in the jar, so if it's trying to store compiled files in the same location for later use it will fail.

I don't know for sure this is the case, but unless someone that is familiar with it can help, it's probably worth the time to try.
Interesting. That is good to know and sounds like a good lead. So it works differently in the B4J environment even in release mode?
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
So it works differently in the B4J environment even in release mode?
As I don't know Jasper reports, I can't answer that definitively. As no one else has chimed in, it appears that you may be trailblazing with this.

Are you using Java11? have you tried with Java 8?
 
Upvote 0

cjpryor

Active Member
Licensed User
As I don't know Jasper reports, I can't answer that definitively. As no one else has chimed in, it appears that you may be trailblazing with this.

Are you using Java11? have you tried with Java 8?
I should have been more clear, I meant to ask if the files folder is read only when Running the program in the B4J IDE in release mode.

:)

I am using Java 11. I have a different java library wrapper that I wrote around Jasper Reports which also uses Java 11 and works fine. Also, the version of Dynamic Jasper that I am using says it is for Java 11. This version of Dynamic Jasper is using the same version of Jasper Reports that my library wrapper uses. Finally, my standalone jar that works fine wraps the same Dynamic Jasper and Jasper Reports and uses Java 11.

The biggest thing I am wondering about right now is why all of this works in the B4J IDE but not in the application packaged from the B4J IDE. That is why I think I need to research and experiment with the packager. Your observation about the files folder being read only in the packaged application is the kind of information that is very helpful to me right now.

:)

Thanks again!
 
Upvote 0

cjpryor

Active Member
Licensed User
But first, I am going to devote a short amount of time developing the HTML report workaround so I have something to release ASAP. I have a couple of distributors waiting for these new reporting features!
 
Upvote 0

cjpryor

Active Member
Licensed User
It seems building dynamic reports in HTML and then displaying them in the default browser is quite effective. I was able to re-purpose DBUtils.ExecuteHtml to meet my needs. I could not use it out of the box because I store field headings in a separate table from the field values. This gives people the flexibility to use whatever names they want for their field values. Also, several of my reports are actually a list of field:value pair rows going down the page rather than columns of values going across the page.

Perhaps I will create a new forum entry on that approach later if people are interested. It sure does eliminate the complexity of trying to get Dynamic Jasper to work when packaged in a B4J application.
 
Upvote 0
Top