实例化Java对象时发生异常(ColdFusion)

时间:2012-09-17 15:40:40

标签: java coldfusion itext

我前段时间为adding a link to a pdf找到了这个解决方案。如果偶尔使用它,它就像魅力一样(每次使用之间重启服务器)。我发现由于某些原因(我对java和iText不是很有经验)尝试再次运行此脚本(不重启)时,ColdFusion会返回错误:

  

对象实例化异常。

     

实例化Java对象时发生异常。班级   不能是接口或抽象类。错误:''。

然后,

ColdFusion表示导致错误的行似乎在:

pdfReader = createObject("java","com.lowagie.text.pdf.PdfReader").init(inputPath);

谁更了解这个,有解决方案还是可以解释为什么会这样?我认为java内部创建的java对象在某种程度上“幸存”但当然不能在CF内生存。

堆栈追踪:

java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at coldfusion.runtime.java.JavaProxy.CreateObject(JavaProxy.java:166)
    at coldfusion.runtime.java.JavaProxy.invoke(JavaProxy.java:80)
    at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:2360)
    at cfSched_PushJobs2MultiPress32ecfm1907554548._factor16(E:\Inetpub\DashBoards\MultiPress\Sched_PushJobs2MultiPress3.cfm:549)
    at cfSched_PushJobs2MultiPress32ecfm1907554548._factor17(E:\Inetpub\DashBoards\MultiPress\Sched_PushJobs2MultiPress3.cfm:547)
    at cfSched_PushJobs2MultiPress32ecfm1907554548._factor45(E:\Inetpub\DashBoards\MultiPress\Sched_PushJobs2MultiPress3.cfm:543)
    at cfSched_PushJobs2MultiPress32ecfm1907554548._factor25(E:\Inetpub\DashBoards\MultiPress\Sched_PushJobs2MultiPress3.cfm)
    at cfSched_PushJobs2MultiPress32ecfm1907554548._factor49(E:\Inetpub\DashBoards\MultiPress\Sched_PushJobs2MultiPress3.cfm:512)
    at cfSched_PushJobs2MultiPress32ecfm1907554548._factor51(E:\Inetpub\DashBoards\MultiPress\Sched_PushJobs2MultiPress3.cfm:509)
    at cfSched_PushJobs2MultiPress32ecfm1907554548._factor53(E:\Inetpub\DashBoards\MultiPress\Sched_PushJobs2MultiPress3.cfm:461)
    at cfSched_PushJobs2MultiPress32ecfm1907554548._factor58(E:\Inetpub\DashBoards\MultiPress\Sched_PushJobs2MultiPress3.cfm:213)
    at cfSched_PushJobs2MultiPress32ecfm1907554548._factor129(E:\Inetpub\DashBoards\MultiPress\Sched_PushJobs2MultiPress3.cfm:207)
    at cfSched_PushJobs2MultiPress32ecfm1907554548._factor146(E:\Inetpub\DashBoards\MultiPress\Sched_PushJobs2MultiPress3.cfm:102)
    at cfSched_PushJobs2MultiPress32ecfm1907554548.runPage(E:\Inetpub\DashBoards\MultiPress\Sched_PushJobs2MultiPress3.cfm:1)
    at coldfusion.runtime.CfJspPage.invoke(CfJspPage.java:231)
    at coldfusion.tagext.lang.IncludeTag.doStartTag(IncludeTag.java:416)
    at coldfusion.filter.CfincludeFilter.invoke(CfincludeFilter.java:65)
    at coldfusion.filter.ApplicationFilter.invoke(ApplicationFilter.java:360)
    at coldfusion.filter.MonitoringFilter.invoke(MonitoringFilter.java:40)
    at coldfusion.filter.PathFilter.invoke(PathFilter.java:94)
    at coldfusion.filter.ExceptionFilter.invoke(ExceptionFilter.java:70)
    at coldfusion.filter.BrowserDebugFilter.invoke(BrowserDebugFilter.java:79)
    at coldfusion.filter.ClientScopePersistenceFilter.invoke(ClientScopePersistenceFilter.java:28)
    at coldfusion.filter.BrowserFilter.invoke(BrowserFilter.java:38)
    at coldfusion.filter.NoCacheFilter.invoke(NoCacheFilter.java:46)
    at coldfusion.filter.GlobalsFilter.invoke(GlobalsFilter.java:38)
    at coldfusion.filter.DatasourceFilter.invoke(DatasourceFilter.java:22)
    at coldfusion.filter.CachingFilter.invoke(CachingFilter.java:62)
    at coldfusion.CfmServlet.service(CfmServlet.java:200)
    at coldfusion.bootstrap.BootstrapServlet.service(BootstrapServlet.java:89)
    at jrun.servlet.FilterChain.doFilter(FilterChain.java:86)
    at coldfusion.monitor.event.MonitoringServletFilter.doFilter(MonitoringServletFilter.java:42)
    at coldfusion.bootstrap.BootstrapFilter.doFilter(BootstrapFilter.java:46)
    at jrun.servlet.FilterChain.doFilter(FilterChain.java:94)
    at jrun.servlet.FilterChain.service(FilterChain.java:101)
    at jrun.servlet.ServletInvoker.invoke(ServletInvoker.java:106)
    at jrun.servlet.JRunInvokerChain.invokeNext(JRunInvokerChain.java:42)
    at jrun.servlet.JRunRequestDispatcher.invoke(JRunRequestDispatcher.java:286)
    at jrun.servlet.ServletEngineService.dispatch(ServletEngineService.java:543)
    at jrun.servlet.jrpp.JRunProxyService.invokeRunnable(JRunProxyService.java:203)
    at jrunx.scheduler.ThreadPool$DownstreamMetrics.invokeRunnable(ThreadPool.java:320)
    at jrunx.scheduler.ThreadPool$ThreadThrottle.invokeRunnable(ThreadPool.java:428)
    at jrunx.scheduler.ThreadPool$UpstreamMetrics.invokeRunnable(ThreadPool.java:266)
    at jrunx.scheduler.WorkerThread.run(WorkerThread.java:66)
Caused by: java.io.IOException: Map failed
    at sun.nio.ch.FileChannelImpl.map(FileChannelImpl.java:758)
    at com.lowagie.text.pdf.MappedRandomAccessFile.init(Unknown Source)
    at com.lowagie.text.pdf.MappedRandomAccessFile.<init>(Unknown Source)
    at com.lowagie.text.pdf.RandomAccessFileOrArray.<init>(Unknown Source)
    at com.lowagie.text.pdf.RandomAccessFileOrArray.<init>(Unknown Source)
    at com.lowagie.text.pdf.PRTokeniser.<init>(Unknown Source)
    at com.lowagie.text.pdf.PdfReader.<init>(Unknown Source)
    at com.lowagie.text.pdf.PdfReader.<init>(Unknown Source)
    ... 48 more
Caused by: java.lang.OutOfMemoryError: Map failed
    at sun.nio.ch.FileChannelImpl.map0(Native Method)
    at sun.nio.ch.FileChannelImpl.map(FileChannelImpl.java:755)
    ... 55 more

2 个答案:

答案 0 :(得分:1)

错误给出了问题。转到第一个“引起”行:

java.lang.OutOfMemoryError: Map failed     at sun.nio.ch.FileChannelImpl.map0(Native Method) 

根本原因是你内存不足。尝试增加JVM的可用内存。

答案 1 :(得分:1)

这不是一个庞大的文件,但很大程度上取决于可用的服务器内存量以及其他进程使用了​​多少内存。您可能想尝试为阅读器使用RandomAccessFileOrArray并缓冲编写器输出。看看是否有帮助。另外,请确保关闭压模和输出流。

// use random access when reading 
raf = createObject("java", "com.lowagie.text.pdf.RandomAccessFileOrArray").init(inputPath, false, true);
pdfReader = createObject("java", "com.lowagie.text.pdf.PdfReader").init( raf, javacast("null", ""));
... 
// buffer the output
fos = createObject("java", "java.io.FileOutputStream");
outStream = createObject("java", "java.io.BufferedOutputStream").init( fos.init( outputPath ) );
pdfStamper = createObject("java", "com.lowagie.text.pdf.PdfStamper").init( pdfReader, outStream );