简体   繁体   English

Jasper报路径问题,在App server上运行时找不到.jasper文件

[英]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?当在 Tomcat(Eclipse w/debugger)中运行时,你应该如何获取 JasperFillManager.fillReport JasperFillManager.fillReport()使用的 .jasper 文件(比如 InputStream)? Currently our.jasper files are within /WEB-INF/jasper .目前 our.jasper 文件位于/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.如果在从 Eclipse 运行 Tomcat 时对其进行调试,则System.getProperty("user.dir")返回C:/Eclipse...但显然,当它部署到服务器时,该路径将有所不同。

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 .如果您不打算在创建后替换 .jasper 文件,那么您可以使用 resources 和getResourcesAsStream

I believe you can use the application object (assuming you're using JSPs rather than servlets - I've not been using them)我相信您可以使用应用程序 object(假设您使用的是 JSP 而不是 servlets - 我没有使用过它们)

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.通过更改 Eclipse 中的 Tomcat 启动配置工作目录,我已经设法从 tomcat/eclipse 运行此工作。这让您只需将相对路径传递给 Java 代码中的 fillReport()。 But I've yet to try testing from within websphere... (something tells me I'll be cursing IBM again soon).但我还没有尝试从 websphere 内部进行测试......(有些事情告诉我我很快就会再次诅咒 IBM)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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