2017-05-25 72 views
0

我有一個servlet使用另一個class命名Converter,此類中使用,我已經把WEB-INF/lib但仍試圖使用這個類,我得到java.lang.ClassNotFoundException的時候,我已經嘗試了無數一些外部罐這裏的解決方案,但仍然沒有工作:的Servlet - 包括從另一個類等罐子

  • 把罐子放在classpath
  • 把罐子在WEB-INF/classes中

而且他們的非正常工作,這裏是有關部分從我servlet

private Converter htmlCon = new Converter(webInfPath); 

protected void doPost(HttpServletRequest request, 
      HttpServletResponse response) throws ServletException, IOException { 
     StringBuffer jb = new StringBuffer(); 
     String line = null; 
     try { 
      BufferedReader reader = request.getReader(); 
      while ((line = reader.readLine()) != null) { 
       jb.append(line); 
      } 
     } catch (IOException IOE) { 
      IOE.printStackTrace(); 
     } 
     try { 
      htmlCon.createPdf(jb.toString(), "pdf.pdf"); 
     } catch (DocumentException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 

Converter

package com.mataf.converters; 

import java.io.File; 
import java.io.FileOutputStream; 
import java.io.IOException; 
//the external jars 
import org.xhtmlrenderer.pdf.ITextRenderer; 

import com.lowagie.text.DocumentException; 

public class Converter { 

    private Types m_type; 
    private String m_pathToCreateFileIn; 

    public Converter(String i_path) { 
     this.m_pathToCreateFileIn = i_path; 
    } 

    public void createPdf(String html, String fileName) throws IOException, DocumentException{ 

     ITextRenderer renderer = new ITextRenderer(); 
     // if you have html source in hand, use it to generate document object 
     renderer.setDocumentFromString(html); 
     renderer.layout(); 
     String fileNameWithPath = m_pathToCreateFileIn + File.separator + "PDF-FromHtmlString.pdf"; 
     FileOutputStream fos = new FileOutputStream(fileNameWithPath); 
     renderer.createPDF(fos); 
     fos.close(); 
     System.out.println("File 2: '" + fileNameWithPath + "' created."); 
     System.out.println(html); 
     System.out.println(fileName); 
    } 

} 

全部stacktrace

com.ibm.ws.webcontainer.servlet.ServletWrapper run SRVE8052E: Logging ClassNotFoundException 
           java.lang.ClassNotFoundException: class java.lang.NullPointerException: null 
    at java.beans.Beans.instantiate(Beans.java:190) 
    at java.beans.Beans.instantiate(Beans.java:75) 
    at com.ibm.ws.webcontainer.servlet.ServletWrapper$1.run(ServletWrapper.java:1461) 
    at com.ibm.ws.security.util.AccessController.doPrivileged(AccessController.java:118) 
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.loadServlet(ServletWrapper.java:1450) 
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.load(ServletWrapper.java:1348) 
    at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:980) 
    at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3703) 
    at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:304) 
    at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:962) 
    at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1662) 
    at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:195) 
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:458) 
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:522) 
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:311) 
    at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:87) 
    at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165) 
    at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217) 
    at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161) 
    at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138) 
    at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204) 
    at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775) 
    at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905) 
    at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1783) 
+0

當詢問異常時,**總是**發佈異常的完整堆棧跟蹤。 –

+0

添加,謝謝。 –

+0

@JBNizet - 添加堆棧跟蹤,請告訴是否有其他需要的東西。 –

回答