【问题标题】:Dynamically injecting JasperReports font file into webapp将 JasperReports 字体文件动态注入 webapp
【发布时间】:2016-07-03 21:07:34
【问题描述】:

我们有一个 WebService,它接收报告的名称及其参数,并调用 JRPdfExporter。

由于用户可以在运行时添加报表,我们需要一种方法将 Jasper jar 字体文件动态添加到类路径中,以便用户添加的任何新字体都可以添加到 Jasper 类路径中。

我们正在使用此代码尝试将新 jar 注入到类路径中,但没有成功

URLClassLoader sysloader = (URLClassLoader) ClassLoader.getSystemClassLoader();
Class sysclass = URLClassLoader.class;

try {
    Method method = sysclass.getDeclaredMethod("addURL", new Class[]{URL.class});
    method.setAccessible(true);
    method.invoke(sysloader, new Object[] {u});
} catch (Throwable t) {
    t.printStackTrace();
    throw new IOException("Error, could not add URL to system classloader");
}

我得到的错误是

net.sf.jasperreports.engine.JRRuntimeException: net.sf.jasperreports.engine.JRException: Input stream not found at : fonts/fontsfamily1415192514231.xml

关于如何做到这一点的任何想法?

或者有更好的选择吗?

【问题讨论】:

    标签: java fonts jasper-reports


    【解决方案1】:

    我通过“简化”在特定文件夹中搜索 JAR 字体文件、打开它们并解压缩所有必要的文件/文件夹来解决此问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多