今天在学习dhtmlx一个把grid导出为pdf的小例子时,出现如下错误:
java.lang.UnsupportedClassVersionError: Bad version number in .class file (unable to load class com.pdfjet.PDF)
at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:1851)
at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:890)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1354)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1233)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at com.dhtmlx.xml2pdf.PDFWriter.createPDF(PDFWriter.java:85)
at com.dhtmlx.xml2pdf.PDFWriter.generate(PDFWriter.java:62)
at test.PDFGenerator.doPost(PDFGenerator.java:22)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:595)
由上面的stack trace可以得知此错误是因为类加载器无法加载类com.pdfjet.PDF所导致。经查看发现原来是因为com.pdfjet.PDF所在的jar(PDFjet.jar)是使用JDK1.6.0_18编译打包的(jar文件里面MANIFEST.MF文件里面记录着该jar对应的JDK的版本),而我的tomcat是运行在JDK1.5.0_14上的,所以出现此错误。解决办法很简单,让我的tomcat运行在JDK1.6上就行了。