Primefaces generating java.lang.NoClassDefFoundError: com/lowagie/text/Document on call method to generate PDF for fileDownload

Primefaces generating java.lang.NoClassDefFoundError: com/lowagie/text/Document on call method to generate PDF for fileDownload

我需要你的帮助来解决在 iText jar 中找不到 class com/lowagie/text/Document 的问题。 Primefaces 版本为 5.0,iText 版本为 2.1.7。当我在 actionListner 中添加方法名称以调用它以便从方法生成 PDF 文件并使其在单击命令按钮时可下载时,会生成错误。

我确实删除了所有 JAR 并一个一个添加它们,但问题仍然相同。所有 JAR 都是唯一的,我正在使用 Jdeveloper。

Bean代码为:

public void createPdf1() {
    com.lowagie.text.Document doc = new com.lowagie.text.Document(PageSize.A4, 50, 50, 50, 50);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    ByteArrayInputStream in ;
    try {

        PdfWriter writer;

        writer = PdfWriter.getInstance(doc, out);

        doc.open();
        PdfPTable table = new PdfPTable(1);
        PdfPCell cell = new PdfPCell(new Phrase("First PDF"));
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setRunDirection(PdfWriter.RUN_DIRECTION_LTR);
        table.addCell(cell);
        doc.add(table);
        in = new ByteArrayInputStream(out.toByteArray());
        file = new DefaultStreamedContent(in, "application/pdf", "xxx.pdf");
        System.out.println("INSIDE");
    } catch (Exception e) {
        e.printStackTrace();
    }
}

而 jsf 代码是我关注的展示:

<p:commandButton value="Download" ajax="false" onclick="PrimeFaces.monitorDownload(start, stop);" icon="ui-icon-arrowthick-1-s" actionListner="#{pdf.createPdf1}">
    <p:fileDownload value="#{pdf.file}" />
</p:commandButton>

在单击 commandButton 时出现错误:

javax.faces.el.EvaluationException: java.lang.NoClassDefFoundError: com/lowagie/text/Document at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102) at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102) at javax.faces.component.UICommand.broadcast(UICommand.java:315) at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:787) at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1252) at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl._invokeApplication(LifecycleImpl.java:973) at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl._executePhase(LifecycleImpl.java:354) at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:202) at javax.faces.webapp.FacesServlet.service(FacesServlet.java:508) Caused By: java.lang.ClassNotFoundException: com.lowagie.text.Document at weblogic.utils.classloaders.GenericClassLoader.findLocalClass(GenericClassLoader.java:297) at weblogic.utils.classloaders.GenericClassLoader.findClass(GenericClassLoader.java:270) at weblogic.utils.classloaders.ChangeAwareClassLoader.findClass(ChangeAwareClassLoader.java:64) at java.lang.ClassLoader.loadClass(ClassLoader.java:305) at java.lang.ClassLoader.loadClass(ClassLoader.java:246) at weblogic.utils.classloaders.GenericClassLoader.loadClass(GenericClassLoader.java:179) at weblogic.utils.classloaders.ChangeAwareClassLoader.loadClass(ChangeAwareClassLoader.java:43)

iText WAR 文件保存在 /lib 文件夹下并且运行良好。兼容版本为iText 2.1.7 请参考指南中的Dependencies