maven - Adobe AEM 与 IText PDF 7.1.x,java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
问题描述
我在AEM 6.5中使用IText PDF(7.1.x)。我已将 IText7 依赖项添加到 AEM 作为 AEM 主项目中的子项目。代码正在成功构建,但我得到了
java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at com.itextpdf.io.font.FontRegisterProvider.<clinit>(FontRegisterProvider.java:68)
at com.itextpdf.io.font.FontProgramFactory.<clinit>(FontProgramFactory.java:67)
at com.itextpdf.kernel.font.PdfFontFactory.createFont(PdfFontFactory.java:234)
at com.itextpdf.kernel.font.PdfFontFactory.createFont(PdfFontFactory.java:220)
at com.itextpdf.kernel.font.PdfFontFactory.createFont(PdfFontFactory.java:162)
at com.itextpdf.kernel.font.PdfFontFactory.createFont(PdfFontFactory.java:93)
at com.itextpdf.layout.RootElement.getDefaultProperty(RootElement.java:178)
at com.itextpdf.layout.Document.getDefaultProperty(Document.java:342)
............
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory not found by com.pdfgen
请在下面找到子项目的POM文件
<?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>
<parent>
<groupId>com.pdfgen.itexttest</groupId>
<artifactId>pdfgen_itexttest</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>pdfgen_itexttest.itext</artifactId>
<packaging>jar</packaging>
<name>Pdfgen IText POC</name>
<description>IText bundle for POC/description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<includeArtifactIds>kernel,layout,bcprov-jdk15on,slf4j-api,slf4j-simple</includeArtifactIds>
<stripVersion>true</stripVersion>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>biz.aQute.bnd</groupId>
<artifactId>bnd-maven-plugin</artifactId>
<executions>
<execution>
<id>bnd-process</id>
<goals>
<goal>bnd-process</goal>
</goals>
<configuration>
<bnd><![CDATA[
Bundle-Category: ITextHtml2pdf
Bundle-SymbolicName: com.pdfgen
Import-Package: javax.annotation;version=0.0.0,
!sun.*,
org.slf4j,
org.bouncycastle.asn1,
*
Include-Resource: target/dependency/slf4j-api.jar,
target/dependency/slf4j-simple.jar
Bundle-ClassPath: .,slf4j-api
Export-Package: com.itextpdf.*
]]></bnd>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.caconfig.bnd-plugin</artifactId>
<version>1.0.2</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>biz.aQute.bnd</groupId>
<artifactId>bnd-baseline-maven-plugin</artifactId>
<configuration>
<failOnMissing>false</failOnMissing>
</configuration>
<executions>
<execution>
<id>baseline</id>
<goals>
<goal>baseline</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>kernel</artifactId>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>layout</artifactId>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>io</artifactId>
</dependency>
</dependencies>
</project>
我已经尝试了一段 PDF 生成代码,它在 AEM 之外完美运行,但我在 AEM 中遇到了上述错误。
解决方案
slf4j-api 包在 AEM 上可用 - 无需导入它。实际上,您自己导入它可能是您的问题的原因。请在不导入的情况下重试 - 并确保您的依赖项定义为 slf4j 设置了与您的 AEM 安装相匹配的版本。
除此之外,我建议您切换到像 filevault-package-maven-plugin 这样的 Maven 插件来嵌入外部依赖项。
推荐阅读
- roomle - 如果模型有类似玻璃的材料,Roomle 模型会从地板上掉下来
- c++ - 是否可以使用 free 释放通过 new 创建的动态对象?
- r - R中的分组堆积条形图?
- python - 带有分页的 SQLAlchemy 游标方法
- android - 是否可以使用 Unity Fragment 而不是 UnityPlayerActivity?
- visual-studio-code - 如何为 Teams Tab 跨设备调试设置 ngrok
- javascript - 对象作为 React 子对象无效(找到:对象与键 {seconds, nanoseconds})。(Firebase、React、材料表)
- networking - 如何允许 ARP?
- c# - 加载 .xlsx 文件会引发“日期格式不正确”
- python - python beautifulsoup4 从 find_all 结果中查找 href 链接