>我在将数据表导出为 PDF 时遇到问题。我使用:
<primeFacesVersion>3.5</primeFacesVersion>
和:
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.7</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.lowagie</groupId>
<artifactId>itext</artifactId>
<version>2.1.7</version>
<scope>provided</scope>
</dependency>
在 XHTML 中:
<h:form id="listForm">
<h:panelGrid width="100%" columns="1">
<p:dataTable id="listTable" var="employee"
value="#{employeeBean.result}" paginator="true" dynamic="true"
rows="10" rowKey="#{item.id}" rowIndexVar="i" selection="#{employeeBean.selected}"
emptyMessage="#{label['no.record.found']}" sortDescMessage="#{label['sort.desc.message']}"
paginatorPosition="bottom" sortAscMessage="#{label['sort.asc.message']}"
update="listTable">
.....
<h:commandLink value="#{label['PDF']}" ajax="false" icon="excel-icon">
<p:dataExporter type="pdf" target="listTable" fileName="emplList"/>
</h:commandLink>
</h:form>
抛出此异常是行不通的:
SEVERE: Servlet.service() for servlet [Faces Servlet] in context with path [] threw exception [com/lowagie/text/Phrase] with root cause
java.lang.ClassNotFoundException: com.lowagie.text.Phrase
有了这个,
<scope>provided</scope>
你基本上是在告诉 Maven,你已经处理好了这个依赖关系在运行时类路径中是保证存在的,因此 Maven 不需要将其包含在构建中。 也就是说,iText JAR文件不会出现在WAR的/WEB-INF/lib
文件夹中,并且假设目标servletcontainer已经提供了开箱即用的它(如Java EE/servlet库)。
但是,据我所知,世界上没有一个servletcontainer将iText捆绑在其库中。此外,如果您实际上修改了servletcontainer的库以包含iText,那么您肯定会在问题中明确提及它。所以,我相信你只是在Maven配置中犯了一个错误。也许您复制粘贴了一个示例 Maven 坐标,而没有真正理解其含义。相应地修复它:
<scope>compile</scope>
或者只是完全删除它,它已经是默认设置了。
另请参阅:
- Maven 依赖项作用域