访问 jar 文件中的报告的问题 [英] Problems to access a report in a jar file

查看:18
本文介绍了访问 jar 文件中的报告的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含多个报告(文件 .jasper)的 jar 应用程序,我获取报告路径的方式是:

I have a jar application that contains several reports (files .jasper) and the way that I get the path of the report is:

getClass().getResource("/reportes/mireporte.jasper").toString();

但是当我执行我得到下一个错误:FileNotFoundException虽然当我用 winrar 打开它时报告在 jar 文件中.

but when I execute I get the next error: FileNotFoundException although the report is within the jar file when I open it with the winrar.

我的问题是:

  1. 这是获取 jar 文件中报告路径的方法吗?
  2. 是否可以打开 jar 文件中的报告?

推荐答案

为什么要将资源转换为 String ??

Why are you converting the resource to String ??

尝试使用(取决于你想如何使用资源):

Try to use (depending on how you want to use the resource):

  • getResource("/report/mireporte.jasper").getFile()

getResource("/report/mireporte.jasper").getInputStream()

'getResource' 返回的对象是 URL:

Returned object from 'getResource' is URL:

这篇关于访问 jar 文件中的报告的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆