Primefaces生成java.lang.NoClassDefFoundError:com / lowagie / text / Document on call方法为fileDownload

时间:2015-07-15 19:53:46

标签: jsf pdf primefaces itext jdeveloper

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

我试图删除所有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.E​​valuationException:java.lang.NoClassDefFoundError:   com / lowagie / text / Document at   javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102)     在   com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)     在javax.faces.component.UICommand.broadcast(UICommand.java:315)at   javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:787)     在   javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1252)     在   oracle.adfinternal.view.faces.lifecycle.LifecycleImpl._invokeApplication(LifecycleImpl.java:973)     在   oracle.adfinternal.view.faces.lifecycle.LifecycleImpl._executePhase(LifecycleImpl.java:354)     在   oracle.adfinternal.view.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:202)     在javax.faces.webapp.FacesServlet.service(FacesServlet.java:508)   引发者:java.lang.ClassNotFoundException:com.lowagie.text.Document     在   weblogic.utils.classloaders.GenericClassLoader.findLocalClass(GenericClassLoader.java:297)     在   weblogic.utils.classloaders.GenericClassLoader.findClass(GenericClassLoader.java:270)     在   weblogic.utils.classloaders.ChangeAwareClassLoader.findClass(ChangeAwareClassLoader.java:64)     在java.lang.ClassLoader.loadClass(ClassLoader.java:305)at   java.lang.ClassLoader.loadClass(ClassLoader.java:246)at   weblogic.utils.classloaders.GenericClassLoader.loadClass(GenericClassLoader.java:179)     在   weblogic.utils.classloaders.ChangeAwareClassLoader.loadClass(ChangeAwareClassLoader.java:43)

1 个答案:

答案 0 :(得分:0)

iText WAR文件保存在/ lib文件夹下,并且运行正常。兼容版本为iText 2.1.7,请参阅指南中的依赖项。