views:

751

answers:

3

When I call the jrxml file through .load(), its throw a exception FileNotfoundException. I have tried with absolute path, but it does not work. Please help.

A: 

FileNotFoundException generally means the file is not there. Get the path from your code and paste it in you filesystem explorer and see if it exists.

If it does, it means it is for some reason inaccessible:

This exception will be thrown by the FileInputStream, FileOutputStream, and RandomAccessFile constructors when a file with the specified pathname does not exist. It will also be thrown by these constructors if the file does exist but for some reason is inaccessible, for example when an attempt is made to open a read-only file for writing.

Bozho
A: 

You should always use absolute paths in Java IO stuff. Apparently the one you tried was plain wrong. Maybe you just guessed it based on the deploy location of the webapp. You shouldn't do that. If the jrxml file is actually located in the webcontent, then you can use ServletContext#getRealPath() to convert a relative web path to an absolute disk file system path which you in turn can use further in the usual Java IO stuff.

Assuming that file.jrxml is located in webcontent root (e.g. accessible by http://example.com/contextname/file.jrxml), here's an example:

String absolutePath = getServletContext().getRealPath("file.jrxml");
File file = new File(absolutePath);
BalusC
A: 

It depends on how you give it the reference to the file. Looking at the documentation for the JRXmlLoader http://jasperreports.sourceforge.net/api/net/sf/jasperreports/engine/xml/JRXmlLoader.html you can see that you can pass it in a reference to a File object. You are probably just passing in a string and that might be wrong.

Try something like String path = "/tmp/test.jrmxl"; File jrxmlFile = new File(path); JasperDesign jasperDesign = JRXmlLoader.load(jrxmlFile); with the appropriate try/catch and more and then debug on the file first before you worry about the loader.

You should probably get some of the jasperreports documentation. The books are quite good for that basic stuff.

Manfred Moser