为什么我的Java应用程序看不到* .jrxml? [英] Why My Java Application can't see the *.jrxml?

查看:115
本文介绍了为什么我的Java应用程序看不到* .jrxml?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目具有以下架构:

My project has the following architecture :

我的模板是report1.jrxml,然后当我执行此代码时:

My template is "report1.jrxml", then when i excute this code :

  TableModel model = (TableModel) masterTable.getModel();    
  JRTableModelDataSource data = new JRTableModelDataSource(model);
  String reportSource ="report1.jrxml";
  try {
            JasperReport jr = JasperCompileManager.compileReport(reportSource);
            JasperPrint jp = JasperFillManager.fillReport(jr, null,data);
      } catch (JRException ex) 
      {
            Logger.getLogger(master.class.getName()).log(Level.SEVERE, null, ex);
      }

我收到此错误(我很抱歉法语,但是非常容易理解:p):

I get this error(I'm sorry for the french language, but is quite understandable :p):

Grave: null
net.sf.jasperreports.engine.JRException: java.io.FileNotFoundException: report1.jrxml (Le fichier spécifié est introuvable)
    at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:176)
    at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:156)
    at net.sf.jasperreports.engine.JasperCompileManager.compile(JasperCompileManager.java:171)
    at net.sf.jasperreports.engine.JasperCompileManager.compileReport(JasperCompileManager.java:448)
    at testjasper.master.jButton1ActionPerformed(master.java:319)
    at testjasper.master.access$900(master.java:25)
    at testjasper.master$FormListener.actionPerformed(master.java:259)

Netbeans说该文件不能找到了,但正如你在截图中看到的,我ts存在吗?
如何解决这个问题?
相反,问题是什么?
我的问候。 :p

Netbeans says that the file can't be found , but as you can see in the screenshot, its exists ? How can I solve this "problem" ? rather, what's the problem ? My regards. :p

推荐答案

Jasper报告看不到它,因为该文件是嵌入式资源(它不作为文件存在,但Jar文件中的条目)

Jasper reports can't see it because the file is an embedded resource (it doesn't exist as a file, but a entry in the Jar file)

您需要使用 getClass()获取对它的引用.getResource(/ testjasper / report1.jrxml)将返回 URL

从内存中,你应该能够Jasper a InputStream ,这可以通过使用 URL#openConnection

From memory, you should be able to Jasper a InputStream, this can be achieved by using URL#openConnection

这篇关于为什么我的Java应用程序看不到* .jrxml?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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