iText ClassNotFound Exception
I'm using iText library to work with Acrobat Forms. The servlet compiled without any errors. I imported the external jar files of iText. After compiling, i packaged and prepared an executable .war file (Main.war) and pasted it in the deploy folder of jboss. However, on executing, i get a ClassNotFoundException Error.
Here's the stack trace
java.lang.ClassNotFoundException: com.itextpdf.text.DocumentException from BaseClassLoader@955d1c{VFSClassLoaderPolicy@13ed0e{name=vfszip:/E:/jboss-5.0.1.GA/server/default/deploy/Main.war/ domain=Clas
sLoaderDomain@1074641{name=vfszip:/E:/jboss-5.0.1.GA/server/default/deploy/Main.war/ parentPolicy=AFTER_BUT_JAVA_BEFORE parent=ClassLoaderDomain@dc9766{DefaultDomain}} roots=[MemoryContextHandler@3161
723[path= context=vfsmemory://5c4o12z-o9ytfs-grndwcq5-1-grndwom8-1y real=vfsmemory://5c4o12z-o9ytfs-grndwcq5-1-grndwom8-1y], ZipEntryHandler@22421558[path=Main.war/WEB-INF/classes context=file:/E:/jbo
ss-5.0.1.GA/server/default/deploy/ real=file:/E:/jboss-5.0.1.GA/server/default/deploy/Main.war/WEB-INF/classes]] delegates=null exported=[] <IMPORT-ALL>NON_EMPTY}}
at org.jboss.classloader.spi.base.BaseClassLoader.loadClass(BaseClassLoader.java:422)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2389)
at java.lang.Class.getConstructor0(Class.java:2699)
at java.lang.Class.newInstance0(Class.java:326)
at java.lang.Class.newInstance(Class.java:308)
at org.jboss.web.tomcat.service.TomcatInjectionContainer.newInstance(TomcatInjectionContainer.java:258)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1006)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:777)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:129)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:601)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)
And here's my servlet code -
import com.itextpd开发者_StackOverflow中文版f.text.DocumentException;
import com.itextpdf.text.pdf.AcroFields;
import com.itextpdf.text.pdf.FdfReader;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.PdfStamper;
import java.io.*;
import java.net.*;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Main extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
response.setContentType("application/pdf");
try{
FdfReader FDF = new FdfReader(request.getInputStream());
System.out.println("*************Recieved inputStream***********");
InputStream is = request.getInputStream();
PdfReader reader = new PdfReader(is, null);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PdfStamper stamper = new PdfStamper(reader, baos);
AcroFields fields = stamper.getAcroFields();
fields.setFields(FDF);
stamper.setFormFlattening(true);
stamper.close();
OutputStream os = response.getOutputStream();
baos.writeTo(os);
os.flush();
}
catch (DocumentException DE)
{
throw new IOException(DE.getMessage());
}
}
public void doPost(HttpServletRequest request,HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
}
Can anyone tell me what's the problem????? Its urgent please..
Sameer
Looks like a DocumentException would be thrown, but the corresponding class can not be found by JBoss.
- Are you sure that the iText .jar gets packaged with your webapp? Maybe have a look at the .WAR file you're deploying and check if the iText library is in there...
- If not (or you don't want to) make sure to put it in the JBoss' lib folder. in
/jboss-as/lib/
or/jboss-as/server/default/lib/
.
Edit: Your JAR should end up having a structure that looks about like this
.
|-- index.html
|-- META-INF
| `-- MANIFEST.MF
|
`-- WEB-INF
|-- classes
| `-- <your code is here>
|
`-- lib
`-- <here are your packaged .jar files>
[Mind, this is simplified and does not show all the files...]
精彩评论