Creating fat jars using maven is pretty simple. But it won’t simply work if you’re using jasper reports and embed fonts into your PDF reports. You’ll probably end up with an exception like the following:
1 2 3 4 5 6 7 8 9 10 |
Exception in thread "main" java.lang.ExceptionInInitializerError at net.sf.jasperreports.engine.fill.JRBaseFiller.(JRBaseFiller.java:104) at net.sf.jasperreports.engine.fill.JRVerticalFiller.(JRVerticalFiller.java:72) at net.sf.jasperreports.engine.fill.JRVerticalFiller.(JRVerticalFiller.java:60) at net.sf.jasperreports.engine.fill.JRFiller.createBandReportFiller(JRFiller.java:201) at net.sf.jasperreports.engine.fill.JRFiller.createReportFiller(JRFiller.java:216) at net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:116) at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:667) at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:983) at EmbeddedFontsExample.main(EmbeddedFontsExample.java:18) |
Problem
The problem comes from the created jasperreports_extension.properties file. Jasper already comes with one pre-packaged. When now a fat-jar is created, maven will probably drop the jasper packaged one in favour of the one created to embed the fonts.
Solution
The simplest solution is, of course, just copying the contents of the jasperreports_extension.properties files into a single one.
Are more elegant solution would be, getting maven to do this. With doing this, you don’t have to bother merging the files manually with each update of jasper reports.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <version>2.3</version> <executions> <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> <configuration> <!-- Define the suffix for the shaded jar. --> <shadedArtifactAttached>true</shadedArtifactAttached> <shadedClassifierName>shaded</shadedClassifierName> <filters> <!-- As some dependencies are signed jars, we have to strip the signature files. --> <filter> <artifact>*:*</artifact> <excludes> <exclude>META-INF/*.SF</exclude> <exclude>META-INF/*.DSA</exclude> <exclude>META-INF/*.RSA</exclude> </excludes> </filter> </filters> <!-- Merge the jasperreports_extension.properties files. --> <transformers> <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> <resource>jasperreports_extension.properties</resource> </transformer> </transformers> </configuration> </execution> </executions> </plugin> </plugins> </build> |
Thank you, saved me a lot of time!
Pleased to hear that 🙂
Saved my life, thanks!
In my case it was even worse, jasper was throwing an exception and while trying to log it it was throwing another one…. so that was real mystery…
Very nice to hear that and you managed to track down the root cause 🙂
Feel free to post your initial exception. It might help others. 😉
Hans Albers Das Beste Von Hans Albers https://chrome.rydultowy.biz/39.html Duke Ellington And Billy Strayhorn Great Times