gpt4 book ai didi

java - net.sf.jasperreports.engine.JRRuntimeException : Could not load the following font

转载 作者:行者123 更新时间:2023-12-01 09:17:55 28 4
gpt4 key购买 nike

我的应用程序使用 JasperReports 生成 PDF 文件。我使用 Assembly Maven 插件为我的应用程序生成一个 jar。

问题是,当我使用命令行 java -cp "PrintOutCore-1.0.jar"com.soprabanking.printout.Launcher 运行 jar 时,出现以下异常:

net.sf.jasperreports.engine.JRRuntimeException: Could not load the following font: 
pdfFontName: DejaVu Sans
pdfEncoding: Identity-H
isPdfEmbedded : true
at net.sf.jasperreports.engine.export.JRPdfExporter.getFont(JRPdfExporter.java:2176)
at net.sf.jasperreports.engine.export.JRPdfExporter.getChunk(JRPdfExporter.java:1967)
at net.sf.jasperreports.engine.export.JRPdfExporter.getPhrase(JRPdfExporter.java:1936)
...

但是当我使用命令行将 jasperreports-fonts jar 添加到类路径时 java -cp "jasperreports-fonts-4.0.0.jar;PrintOutCore-1.0.jar"com.soprabanking.printout.Launcher,问题消失,一切正常。

如何在不通过命令行手动将 jasperreports-fonts jar 添加到类路径的情况下正确运行 jar?

这是我的 pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.soprabanking</groupId>
<version>1.0</version>
<packaging>jar</packaging>
<artifactId>PrintOutCore</artifactId>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.soprabanking</groupId>
<artifactId>PrintOutDao</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<!-- BEGIN Junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.9</version>
<exclusions>
<exclusion>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- https://mvnrepository.com/artifact/xmlunit/xmlunit -->
<dependency>
<groupId>xmlunit</groupId>
<artifactId>xmlunit</artifactId>
<version>1.6</version>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<version>1.3</version>
</dependency>
<!-- FINISH Junit -->
<!-- START jasper dependencies -->
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>6.1.1</version>
</dependency>
<dependency>
<groupId>com.lowagie</groupId>
<artifactId>itext</artifactId>
<version>2.1.7</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.12</version>
</dependency>
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports-fonts</artifactId>
<version>4.0.0</version>
</dependency>
<!-- END jasper dependencies -->
<!-- Begin Apache POI -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.10-FINAL</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.10-FINAL</version>
</dependency>
<!-- FINISH Apache POI -->
<!-- https://mvnrepository.com/artifact/net.contentobjects.jnotify/jnotify -->
<dependency>
<groupId>net.contentobjects.jnotify</groupId>
<artifactId>jnotify</artifactId>
<version>0.94</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20090211</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<!-- Includes the runtime dependencies -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<skipTests>true</skipTests>
<includes>
<include>**/*Accountancy*.java</include>
<include>**/*AccountOfficer*.java</include>
<include>**/*AccountsWithout*.java</include>
<include>**/*AutomaticRev*.java</include>
<include>**/*GeneralSummary*.java</include>
<include>**/*GrandLivre*.java</include>
<include>**/*RevaluationOn*.java</include>
<include>**/*SyntheticGeneral*.java</include>
<include>**/*SyntheticBalance*.java</include>
<include>**/*BceaoBalance*.java</include>
<include>**/*DailyReport*.java</include>
<include>**/*DailyTransaction*.java</include>
<include>com.soprabanking.printout.test.utils.*.java</include>
<include>com.soprabanking.printout.service.reportcreators.xls.XLSUtilsTest.java</include>
<include>com.soprabanking.printout.test.service.ParserXmlUtilsTest.java</include>
</includes>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

最佳答案

经过一番查找,找到了问题的根源。

事实上,在打包时,程序集插件会两次查找文件jasperreports_extension.properties,因此它会删除一个并保留另一个。

解决方案是用 Maven-Shade-plugin 替换 Maven-Assembly-plugin 并为其添加转换器。

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>jasperreports_extension.properties</resource>
</transformer>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>org.springframework.batch.core.launch.support.CommandLineJobRunner</mainClass>
</transformer>
<transformer
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.handlers</resource>
</transformer>
<transformer
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.schemas</resource>
</transformer>
</transformers>
<filters>
<filter>
<artifact>junit:junit</artifact>
<includes>
<include>junit/framework/**</include>
<include>org/junit/**</include>
</includes>
<excludes>
<exclude>org/junit/experimental/**</exclude>
<exclude>org/junit/runners/**</exclude>
</excludes>
</filter>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>

关于java - net.sf.jasperreports.engine.JRRuntimeException : Could not load the following font,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40396715/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com