简体   繁体   中英

Jasper Reports path issues, cannot find .jasper files when running on App server

When running in Tomcat (out of Eclipse w/debugger), how are you supposed to get a.jasper file (say as an InputStream) for JasperFillManager.fillReport() to use? Currently our.jasper files are within /WEB-INF/jasper .

I need a solution that doesn't break based on where you happen to be running the report from. If it's being debugged while running Tomcat from Eclipse, System.getProperty("user.dir") returns C:/Eclipse... but obviously, that path will be different when it's deployed to a server.

How do you get around this?

If you do not plan to replace the.jasper file after it was created then you could use the resources and getResourcesAsStream .

I believe you can use the application object (assuming you're using JSPs rather than servlets - I've not been using them)

InputStream input = new FileInputStream(new File(application.getRealPath("/WEB-INF/jasper")+"/report.jasper"));

I've managed to get this working running from tomcat/eclipse by changing the Tomcat launch configuration working directory from within Eclipse. This lets you just pass a relative path to fillReport() in the Java code. But I've yet to try testing from within websphere... (something tells me I'll be cursing IBM again soon).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM