Servlet - 包括来自其他类的其他罐子

时间:2017-05-25 12:44:16

标签: java servlets

我有servlet使用另一个名为class的{​​{1}},这个类使用了我放在Converter中的一些外部jar,但在尝试使用此类时仍然如此我得到WEB-INF/lib,我在这里尝试了无数的解决方案,但仍然没有解决方案:

  • 将罐子放入java.lang.ClassNotFoundException
  • 将jar放在WEB-INF / classes

其中没有它们起作用,这是我classpath的相关部分:

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

1 个答案:

答案 0 :(得分:1)

请参阅此链接,了解您所看到的例外原因:Odd behavior in WAS 7.0: java.lang.ClassNotFoundException: class java.lang.NullPointerException: null

' WebSphere Application Server中包含的Java 6版本丢失了对Java bug 4256569的修复,它掩盖了失败的实际原因。'

如果您在websphere应用程序中更新Java版本,那么问题的实际原因应该是显而易见的。