我有一个在eclipse中运行良好的应用程序(使用jasper reports
的pdf生成器)。
该应用需要一个放置在src/main/resources/fonts
。
现在我将应用程序导出为可执行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:jar可能找不到包含资源的情况?
答案 0 :(得分:0)
字体不应位于resources/fonts/
中,而应放在jar文件中的fonts/
中。