I have a servlet
that use another class
named Converter
, this class use some external jars that I have put in WEB-INF/lib
but still when trying to use this class I get java.lang.ClassNotFoundException
, I have tries countless solutions here but still non of them work:
- putting the jars in
classpath
. - put the jars under WEB-INF/classes
And non of them work, here is the relevant part from my 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();
}
and 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);
}
}
The full 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)