Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
104 views
in Technique[技术] by (71.8m points)

java - Problems to access a report in a jar file

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();

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.

My questions are:

  1. Is this the way to get the path of a report in a jar files?
  2. Is it possible to open reports that are within of a jar file?
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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()

Returned object from 'getResource' is URL:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...