JWhiz JWhiz - 2 years ago 64
Java Question

Using a .jasper file present within a jar file

We are using

as our reporting tool. Earlier we were using relative paths for
jasper files for filling report and it's working fine.

Now, we want to create a new jar for all compiled
files. i.e a jar containing all
files for our project.

Is there a way to access those
files within a jar file while filling report. Because in documentation, i always see

fillReport(java.lang.String sourceFileName, java.util.Map params)

where, sourcefile is always a path on filesystem.

My question is, is there a way to access compiled
files present within a jar file
and fill report based on those files ?

Essentially what is required is, i need to access
files from a jar file, and then fill reports using that
file and save the generated reports onto a filesystem.

Answer Source

Most APIs worth using will provide overloaded methods to accept input streams. E.G. JasperFillManager.fillReport(InputStream, Map)

To get in InputStream, use Class.getResourceAsStream().

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download