我刚刚完成一个项目,但是当我将其放入生产环境时,JasperReport在font.xml上显示错误。我尝试在终端(linux)上的机器上运行该项目,并且出现相同的错误提示,仅当我在Netebeans上运行时才能工作。为什么要在Netbeans和No终端上工作?
我的项目很简单,我生成PDF并通过电子邮件发送。结构是:
jasperreports_extension.properties:
net.sf.jasperreports.extension.registry.factory.fonts=net.sf.jasperreports.engine.fonts.SimpleFontExtensionsRegistryFactory
net.sf.jasperreports.extension.simple.font.families.arial=fonts.xml
fonts.xml:
<fontFamily name="Arial">
<normal>fonts/Arial.ttf</normal>
<bold>fonts/Arial Bold.ttf</bold>
<italic>fonts/Arial Italic.ttf</italic>
<boldItalic>fonts/Arial Bold Italic.ttf</boldItalic>
<pdfEncoding>Identity-H</pdfEncoding>
<pdfEmbedded>true</pdfEmbedded>
<exportFonts>
<export key="net.sf.jasperreports.html">Arial, Helvetica, sans-serif</export>
<export key="net.sf.jasperreports.xhtml">Arial, Helvetica, sans-serif</export>
</exportFonts>
</fontFamily>
POM:
<dependencies>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
</dependency>
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>5.5.0</version>
<exclusions>
<exclusion>
<groupId>jfree</groupId>
<artifactId>*</artifactId>
</exclusion>
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>*</artifactId>
</exclusion>
<exclusion>
<groupId>org.bouncycastle</groupId>
<artifactId>*</artifactId>
</exclusion>
<exclusion>
<groupId>bouncycastle</groupId>
<artifactId>*</artifactId>
</exclusion>
<exclusion>
<groupId>eclipse</groupId>
<artifactId>*</artifactId>
</exclusion>
<exclusion>
<groupId>org.codehaus.castor</groupId>
<artifactId>*</artifactId>
</exclusion>
<exclusion>
<groupId>xml-apis</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports-fonts</artifactId>
<version>6.0.0</version>
</dependency>
<dependency>
<groupId>net.sourceforge.barbecue</groupId>
<artifactId>barbecue</artifactId>
<version>1.5-beta1</version>
</dependency>
<dependency>
<groupId>pdfbox</groupId>
<artifactId>pdfbox</artifactId>
<version>0.7.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>net.sourceforge.maven-taglib</groupId>
<artifactId>maven-taglib-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<goals>
<goal>taglibdocjar</goal>
</goals>
</execution>
</executions>
</plugin>
<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jasperreports-maven-plugin</artifactId>
<versionRange>[1.0-beta-2,)</versionRange>
<goals>
<goal>compile-reports</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>net.sourceforge.maven-taglib</groupId>
<artifactId>maven-taglib-plugin</artifactId>
<version>2.4</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jasperreports-maven-plugin</artifactId>
<version>1.0-beta-2</version>
<configuration>
<sourceDirectory>src/main/resources</sourceDirectory>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
<compiler>net.sf.jasperreports.engine.design.JRJdtCompiler</compiler>
</configuration>
<dependencies>
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>5.5.0</version>
</dependency>
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>servlet-api</artifactId>
<version>3.0.20100224</version>
</dependency>
</dependencies>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>compile-reports</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
错误:
19/11/18 00:00:00 DEBUG BaseReportFiller.<init>:149 - Fill 1: created for boleto-default
19/11/18 00:00:01 DEBUG BaseReportFiller.<init>:177 - created delayed actions 1 for filler 1
19/11/18 00:00:01 DEBUG ExtensionsEnvironment.createDefaultRegistry:87 - Instantiating extensions registry class net.sf.jasperreports.extensions.DefaultExtensionsRegistry
19/11/18 00:00:01 DEBUG DefaultExtensionsRegistry.getRegistries:150 - Loading registries for cache key sun.misc.Launcher$AppClassLoader@70dea4e
19/11/18 00:00:01 DEBUG JRLoader.collectResources:791 - Found resource jasperreports_extension.properties at jar:file:/home/matheus/Downloads/myProject-1.0.0.jar!/jasperreports_extension.properties in classloader sun.misc.Launcher$AppClassLoader@70dea4e
19/11/18 00:00:01 DEBUG DefaultExtensionsRegistry.loadRegistries:182 - Loading JasperReports extension properties resource jar:file:/home/matheus/Downloads/myProject-1.0.0.jar!/jasperreports_extension.properties
19/11/18 00:00:01 DEBUG DefaultExtensionsRegistry.loadRegistries:264 - Instantiating registry of type net.sf.jasperreports.engine.fonts.SimpleFontExtensionsRegistryFactory for property net.sf.jasperreports.extension.registry.factory.fonts
19/11/18 00:00:01 DEBUG DefaultExtensionsRegistry.instantiateRegistry:289 - Instantiating extensions registry for fonts using factory class net.sf.jasperreports.engine.fonts.SimpleFontExtensionsRegistryFactory
19/11/18 00:00:01 DEBUG FontExtensionsRegistry.ensureFontExtensions:88 - Loading font extensions from fonts.xml
Exception in thread "TestThread" java.lang.ExceptionInInitializerError
at net.sf.jasperreports.engine.fill.JRBaseFiller.<init>(JRBaseFiller.java:111)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:69)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:57)
at net.sf.jasperreports.engine.fill.JRFiller.createBandReportFiller(JRFiller.java:219)
at net.sf.jasperreports.engine.fill.JRFiller.createReportFiller(JRFiller.java:234)
at net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:134)
at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:667)
at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:648)
at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:970)
at br.com.caelum.stella.boleto.transformer.GeradorDeBoleto.geraRelatorio(GeradorDeBoleto.java:119)
at br.com.caelum.stella.boleto.transformer.GeradorDeBoleto.geraPDF(GeradorDeBoleto.java:160)
at br.com.caelum.stella.boleto.transformer.GeradorDeBoleto.geraPDF(GeradorDeBoleto.java:210)
at br.com.caelum.stella.boleto.transformer.GeradorDeBoleto.geraPDFStream(GeradorDeBoleto.java:229)
at br.com.company.test.TestThread.run(TestThread.java:57)
at java.lang.Thread.run(Thread.java:748)
答案 0 :(得分:0)
在@Petter Friberg的建议下,我能够识别出我的错误的真正出处,该错误来自Jasper Report属性文件。
下面是帮助我解决问题的链接: