2012-09-17 72 views
2

前段時間,我發現此解決方案爲adding a link to a pdf。如果偶爾使用,它就像一個魅力一樣(在每次使用之間重新啓動服務器)。我發現,由於某些原因(我不是很有經驗的Java和iText的)嘗試運行此腳本第二次(無需重新啓動)時,ColdFusion的返回錯誤:然後實例化Java對象時發生異常(ColdFusion)

Object instantiation exception.

An exception occurred while instantiating a Java object. The class must not be an interface or an abstract class. Error: ''.

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 
+1

使用Java對象,錯誤的實際原因包含在[堆棧跟蹤](http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSc3ff6d0ea77859461172e0811cbec22c24-7d24.html)。請使用堆棧跟蹤更新您的問題。 – Leigh

回答

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); 
+0

謝謝,我想可能會有足夠的內存,但你的改進可能只是做到這一點。馬上試試這個! –

+0

最終,您可能仍需要增加內存。但嘗試RandomAccessFileOrArray(.. plainRandomAccess)首先不能傷害。 – Leigh

+0

謝謝,您使用RandomAccessFileOrArray建議的解決方案工作正常!我也會檢查內存問題。 –

1

錯誤給出了問題。回到第一個「由...引起」的行:

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

根本原因是您用完內存。嘗試增加可用內存到您的JVM。

+0

這是一個600頁,未優化的86MB pdf文件。由於第一次運行良好,以後不起作用,即使在重新啓動ColdFusion服務之後,我想我可以排除內存問題。 運行上述代碼之前,我將運行優化,將文件大小除以2。 –

+0

謝謝,我將檢查CF管理員中的JVM設置。 –