我需要你的帮助来解决在iText jar中找不到类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>
在单击命令按钮时,我得到错误:
javax.faces.el。EvaluationException: java.lang.NoClassDefFoundError:com/lowagie/text/Document在javax.faces.component.MethodBindingMethodExpressionAdapter.invoke (MethodBindingMethodExpressionAdapter.java: 102)在com.sun.faces.application.ActionListenerImpl.processAction (ActionListenerImpl.java: 102)(uiccommand .java:315javax.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:305java.lang.ClassLoader.loadClass (ClassLoader.java: 246)weblogic.utils.classloaders.GenericClassLoader.loadClass (GenericClassLoader.java: 179)在weblogic.utils.classloaders.ChangeAwareClassLoader.loadClass (ChangeAwareClassLoader.java: 43)
iText WAR文件保存在/lib文件夹下,它工作得很好。兼容的版本是iText 2.1.7,请参考指南中的依赖项。