iText 类未找到异常

发布于 2024-11-30 22:18:24 字数 4817 浏览 2 评论 0原文

我正在使用 iText 库来处理 Acrobat Forms。 servlet 编译后没有任何错误。我导入了iText的外部jar文件。编译完成后,我打包并准备了一个可执行的.war文件(Main.war)并将其粘贴到jboss的deploy文件夹中。但是,在执行时,我收到 ClassNotFoundException 错误。

这是堆栈跟踪

    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)

这是我的 servlet 代码 -

import com.itextpdf.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);
}

}

谁能告诉我问题是什么???很紧急,请..

Sameer

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.itextpdf.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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谁对谁错谁最难过 2024-12-07 22:18:24

看起来会抛出DocumentException,但是JBoss找不到相应的类。

  • 您确定 iText .jar 已与您的 Web 应用程序打包在一起吗?也许查看一下您正在部署的 .WAR 文件并检查 iText 库是否在其中...
  • 如果没有(或者您不想),请确保将其放入 JBoss 的 lib 文件夹中。在 /jboss-as/lib//jboss-as/server/default/lib/ 中。

编辑:
你的 JAR 最终应该有一个看起来像这样的结构

.
|-- index.html
|-- META-INF
|   `-- MANIFEST.MF
|   
`-- WEB-INF
    |-- classes
    |   `-- <your code is here>
    |
    `-- lib
        `-- <here are your packaged .jar files>

[注意,这是简化的并且不显示所有文件...]

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...]

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文