0

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)
Itsik Mauyhas
  • 3,824
  • 14
  • 69
  • 114
  • When asking about an exception, **always** post the complete stack trace of the exception. – JB Nizet May 25 '17 at 12:47
  • @JBNizet - add stack trace, please tell if there is something else needed. – Itsik Mauyhas May 25 '17 at 12:50
  • The JARs belong in the WEB-INF/lib; compiled .class byte code belongs under WEB-INF/classes. Your problem suggests a packaging issue. Open the WAR file and make sure you can see the JAR in the WEB-INF/lib directory. – duffymo May 25 '17 at 12:53
  • If tht's really your full stack trace, what the servlet container can't find is the class of your servlet: com.mataf.ConverterServlet. Is it in that package? Is it part of your war file? Where is it located in the war file? Post the output of `jar tvf yourwarfile.war`. – JB Nizet May 25 '17 at 12:53
  • edit my stack trace, the old one was when I removed the servlet from `classes` folder, hopes that helps. – Itsik Mauyhas May 25 '17 at 13:08
  • @JBNizet - you are right, I have updated my stack trace and the original error is shown. – Itsik Mauyhas May 25 '17 at 13:10

1 Answers1

1

Please see this link for the cause of the exception you are seeing: Odd behavior in WAS 7.0: java.lang.ClassNotFoundException: class java.lang.NullPointerException: null

'The version of Java 6 included in WebSphere Application Server has the lost the fix for Java bug 4256569, which obscures the actual cause of the failure.'

If you update the Java version in your websphere application then the actual cause of the problem should be apparent.

Sam
  • 670
  • 1
  • 6
  • 20