Closed dhombios closed 3 years ago
Can you put these lines somewhere in your code and post here the output? Feel free to use any logging framework instead of System.out
ClassLoader jrClassLoader = JasperCompileManager.class.getClassLoader();
System.out.println("CVC XSD at " + jrClassLoader.getResource("net/sf/jasperreports/customvisualization/component.xsd"));
for (Enumeration<URL> jrExtensions = jrClassLoader.getResources("jasperreports_extension.properties"); jrExtensions.hasMoreElements(); ) {
System.out.println("JR extension at " + jrExtensions.nextElement());
}
Thanks for your help Dadza:
CVC XSD at jar:file:/D:/Dhom/Documents/Projects/Myreport/Test5/Myreport.jar!/net/sf/jasperreports/customvisualization/component.xsd
JR extension at jar:file:/D:/Dhom/Documents/Projects/Myreport/Test5/Myreport.jar!/jasperreports_extension.properties
Additionally, since I posted the issue on github I found a jasperReports library user manual (https://community.jaspersoft.com/sites/default/files/docs/jasperreports-ultimate-guide-3v2_0.pdf) which seems a bit outdated but provides a guide on using CVC from java (page 285). I was going to try following it just in case it's instructions for using extensions can still be used in newer jasperReports versions, even though it is quite probable that many things have changed since 2011
I get it that you have something in your project that creates an uber jar from all the dependencies.
When you do that, you need to take specific care of jasperreports_extension.properties jar resources, which are used by JasperReports to load extensions. See a solution at https://stackoverflow.com/a/35025718
Thanks, now it detects the extension. I'm going to document it on the community wiki, so future users don't open a similar issue to this one if they need a fat jar
However, I still get an error due to not having specified the path to PhantomJs (see below), yet I cannot access the variable that contains it, at least in jasperStudio (com.jaspersoft.jasperreports.components.customvisualization.phantomjs.executable.path
), as jvm is unable to find it:
3514 [main] ERROR net.sf.jasperreports.customvisualization.export.CVElementImageProvider - Generating image for Custom Visualization element element77923161343435128113206065653047908829 failed. net.sf.jasperreports.engine.JRRuntimeException: Chrome and/or PhantomJS not properly configured for server side rendering at net.sf.jasperreports.customvisualization.export.CVElementDefaultImageDataProvider.getImageData(CVElementDefaultImageDataProvider.java:75) at net.sf.jasperreports.customvisualization.export.CVElementImageProvider.createRenderable(CVElementImageProvider.java:134) at net.sf.jasperreports.customvisualization.export.CVElementImageProvider.getImage(CVElementImageProvider.java:86) at net.sf.jasperreports.customvisualization.export.CVElementPdfHandler.exportElement(CVElementPdfHandler.java:58) at net.sf.jasperreports.engine.export.JRPdfExporter.exportGenericElement(JRPdfExporter.java:4141) at net.sf.jasperreports.engine.export.JRPdfExporter.exportElements(JRPdfExporter.java:1290) at net.sf.jasperreports.engine.export.JRPdfExporter.exportPage(JRPdfExporter.java:1210) at net.sf.jasperreports.engine.export.JRPdfExporter.exportReportToStream(JRPdfExporter.java:1074) at net.sf.jasperreports.engine.export.JRPdfExporter.exportReport(JRPdfExporter.java:691) at net.sf.jasperreports.engine.JasperExportManager.exportToPdfFile(JasperExportManager.java:155) at net.sf.jasperreports.engine.JasperExportManager.exportReportToPdfFile(JasperExportManager.java:503) at com.Dhombios.myreport.Report_generator.publish(Report_generator.java:82) at com.Dhombios.myreport.CLI.main(CLI.java:99)
The recommended property to set for PhantomJS is net.sf.jasperreports.phantomjs.executable.path
Also see net.sf.jasperreports.chrome.enabled and net.sf.jasperreports.chrome.executable.path, you can use Chromium/Chrome instead of PhantomJS (which is no longer being developed/maintained).
Thanks again! As soon as I solve some problems related to UTF-8 encoding ( is being shown in the exported report instead of €) I'll update the wiki with a complete tutorial on using both, Chrome and PhantomJS
That might be a bug because this line doesn't explicitly encode to UTF-8. Therefore if the default character encoding of the JVM is not UTF-8, the data can get corrupted.
Can you test if starting your application with -Dfile.encoding=UTF-8 makes a difference?
Yes, that solved it. A workaround can be found here: https://stackoverflow.com/a/14987992/15974273 , which consists in adding the following lines at the start of the main function:
System.setProperty("file.encoding","UTF-8");
Field charset = Charset.class.getDeclaredField("defaultCharset");
charset.setAccessible(true);
charset.set(null,null);
On the other hand, I'm having yet another problem, as the text shown in the CVC component needs to be shown aligned with the top of the viewport, but the hanging dominant-baseline and alignment-baseline attributes get ignored. It seems that, sometimes, it might be solved by changing the display attribute of the svg to block (https://stackoverflow.com/q/21099192/15974273), yet it does not work in this case. However, they work when the report is exported to html and opened with the same chromium executable that I have bundled with the application
Edit 20/5/2021 20:46: A workaround for solving this is to set the dy property of the text to 0.75em, but the resulting top margin might change if several texts with different font sizes are used
Log an issue for the UTF-8 problem, we need to fix the code to properly create the HTML no matter the default charset.
When using a report template that contains a Custom Visualization Component from a custom Java application based on JasperReports Library, Jasper raises an exception due to an unknown entity even though the CVC jar has been added to java path (see the attached POM). According to the wiki (https://community.jaspersoft.com/wiki/custom-visualization-component-v60x), this module just requires specifying the path to PhantomJs to be able to use CVC components in JasperReports Server or JasperReports Studio and the JasperReports Library wiki does not contain any additional infomation about its usage (https://community.jaspersoft.com/wiki/jasperreports-library-reference-materials). Therefore, I initially assumed that it did not require any additional configuration
Nevertheless, as the Exception is still being raised, it seems that some undocumented configuration is required to enable the module. I attach below both, the Error and the POM of the project.
I tried asking before in the Answers section of your community website, but it seems to have little activity (https://community.jaspersoft.com/questions/1183536/it-possible-use-custom-visualization-components-jaspersoft-library)
Thanks in advanced
Raised exception:
POM dependencies section (JasperReports Library version 6.16):