在运行我的程序时获取ClassNotFound异常

时间:2016-05-27 06:12:40

标签: java classnotfoundexception pdfbox apache-tika

获得例外:ClassNotFoundException

我在我的类路径中包含了fontbox和pdfbox jar文件。

package com.KyaHub.action;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

import javax.servlet.http.HttpServletRequest;

import org.apache.tika.exception.TikaException;
import org.apache.tika.metadata.Metadata;
import org.apache.tika.parser.ParseContext;
import org.apache.tika.parser.pdf.PDFParser;
import org.apache.tika.sax.BodyContentHandler;

import org.apache.fontbox.cmap.*;
import org.xml.sax.SAXException;

public class PdfParser {

private HttpServletRequest request;


public String  execute() throws IOException,TikaException, SAXException {

 BodyContentHandler handler = new BodyContentHandler();
 Metadata metadata = new Metadata();
 FileInputStream inputstream = new FileInputStream(new      File("C:/Users/admin/Downloads/cmp_column_width_example.pdf"));              
 ParseContext pcontext = new ParseContext();

 try{
 //parsing the document using PDF parser
 PDFParser pdfparser = new PDFParser(); 
 pdfparser.parse(inputstream, handler, metadata,pcontext);

 //getting the content of the document
 System.out.println("Contents of the PDF :" + handler.toString());

 //getting metadata of the document
 System.out.println("Metadata of the PDF:");
 String[] metadataNames = metadata.names();

 for(String name : metadataNames) {
    System.out.println(name+ " : " + metadata.get(name));
 }


 }
 catch(Exception e)
 {
     e.printStackTrace();
 }
 return "success";
}

//getter and setter
public HttpServletRequest getRequest() {
    return request;
}

public void setRequest(HttpServletRequest request) {
    this.request = request;
}

}

每当我用APJ.AbdulKalamAzad.pdf更改文件名时,我都得到输出。但是当我用另一个pdf文件更改文件名时,我得到了上面提到的例外。

0 个答案:

没有答案