0
我有一個應用程序在eclipse中運行良好(使用jasper reports
的pdf生成器)。 該應用需要放入src/main/resources/fonts
的字體。Runnable jar找不到資源?
現在我將應用程序導出爲可執行jar。正確地在jar中有一個文件夾resources/fonts/
。
總之:當我運行java -jar app.jar
我得到一個異常,資源未找到:
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: net.sf.jasperreports.engine.JRRuntimeException: Could not load the following font :
pdfFontName : Arial
pdfEncoding : Cp1252
isPdfEmbedded : true
at net.sf.jasperreports.engine.export.JRPdfExporter.getFont(JRPdfExporter.java:2152)
at net.sf.jasperreports.engine.export.JRPdfExporter.getChunk(JRPdfExporter.java:1942)
at net.sf.jasperreports.engine.export.JRPdfExporter.getPhrase(JRPdfExporter.java:1911)
at net.sf.jasperreports.engine.export.SimplePdfTextRenderer.getPhrase(SimplePdfTextRenderer.java:88)
at net.sf.jasperreports.engine.export.SimplePdfTextRenderer.render(SimplePdfTextRenderer.java:98)
at net.sf.jasperreports.engine.export.JRPdfExporter.exportText(JRPdfExporter.java:2275)
at net.sf.jasperreports.engine.export.JRPdfExporter.exportElements(JRPdfExporter.java:985)
at net.sf.jasperreports.engine.export.JRPdfExporter.exportFrame(JRPdfExporter.java:2779)
at net.sf.jasperreports.engine.export.JRPdfExporter.exportElements(JRPdfExporter.java:989)
at net.sf.jasperreports.engine.export.JRPdfExporter.exportPage(JRPdfExporter.java:944)
at net.sf.jasperreports.engine.export.JRPdfExporter.exportReportToStream(JRPdfExporter.java:816)
at net.sf.jasperreports.engine.export.JRPdfExporter.exportReport(JRPdfExporter.java:519)
at net.sf.jasperreports.engine.JasperExportManager.exportToPdf(JasperExportManager.java:218)
at net.sf.jasperreports.engine.JasperExportManager.exportReportToPdf(JasperExportManager.java:543)
忽略的JasperReports:什麼都可以當罐子沒有找到包含資源的情況?
忽略報告是我的頭上的事情:1)資源鏈接做得很糟糕,你是如何鏈接代碼中的文件?也許它使用了一個特定的本地路徑,一旦你在eclipe之外運行代碼就會超出範圍? 2)將它添加爲庫? – MSB 2015-03-13 09:56:16