在服務器端,我有一個類用於將SVG文件轉換爲PDF。在Apache Tomcat上部署GWT應用程序
public class PdfHandler {
private File savedFile;
private File svgTempFile;
public PdfHandler(String fileName) {
this.savedFile = new File(File.separator + "documents" + File.separator + fileName);
}
public void convertToPdf(String inputFileName) {
this.svgTempFile = new File(inputFileName);
System.out.println(inputFileName);
if (this.svgTempFile.exists()){
System.out.println("Svg File exists");
}
else {
System.out.println("Svg File not exists");
}
try {
Transcoder transcoder = new PDFTranscoder();
System.out.println("Transcoder created");
FileInputStream fis = new FileInputStream(this.svgTempFile);
System.out.println("Input stream created");
FileOutputStream fos = new FileOutputStream(this.savedFile);
System.out.println("Output stream created");
TranscoderInput transcoderInput = new TranscoderInput(fis);
System.out.println("Transcoder input created");
TranscoderOutput transcoderOutput = new TranscoderOutput(fos);
System.out.println("Transcoder output created");
transcoder.transcode(transcoderInput, transcoderOutput);
System.out.println("Conversion finished");
fis.close();
fos.close();
} catch (Exception ex) {
ex.printStackTrace();
System.out.println("Exception");
} finally {
this.svgTempFile.delete();
System.out.println("File deleted");
}
System.out.println("End of method");
}
}
而且我有一個RPC調用的方法。
public String generatePdf(PayDoc filledDoc) {
//String svgFileName = this.generateSvg(filledDoc);
//String pdfFileName = this.generateFileName("pdf");
PdfHandler pdfHandler = new PdfHandler("myPdf.pdf");
pdfHandler.convertToPdf(File.separator + "documents" + File.separator + "mySvg.svg");
return null;//pdfFileName;
}
在eclipse中所有的工作都很好,但不是在Tomcat上。當我把它在Tomcat RPC失敗,這是Tomcat的控制檯輸出:
\documents\mySvg.svg
Svg File exists
Transcoder created
Input stream created
Output stream created
Transcoder input created
Transcoder output created
File deleted
後,在「文檔」文件夾中我有「mySvg.svg」(還沒有刪除)和「myPdf.pdf」(這是空)。
_「on Tomcat。RPC failed」_失敗如何? tomcat的錯誤日誌裏有什麼? – Baz
java.lang.NoClassDefFoundError:org/w3c/dom/ElementTraversal –