I need your help in solving the issue of not finding the class com/lowagie/text/Document in iText jar. The Primefaces version is 5.0 and the iText version is 2.1.7. The error is generated when I am adding the method name in the actionListner for calling it in order to generate a PDF file from a method and to make it downloadable on the click of a commandButton.
I trued removing all the JARs and adding them one by one and still the issue is the same. All the JARs are unique and I am using Jdeveloper.
The Bean code is:
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();
}
}
And the jsf code is which I followed the showcase:
<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>
On the click of the commandButton, I am getting the error:
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)
The iText WAR file is kept under the /lib folder and it has worked fine. The compatible version is iText 2.1.7 please refer to the Dependencies in the guide.