Hi,
I am developing an application to generated Jasper Report. I am using Netbeans 6.5, jasperReport 3.1.3. I am developing it using Visual web JSF.

My JSP file is

D:/Programs/Java/JasperReports/EmployeeReport/web/Page1.jsp

My report file is stored in

D:/Programs/Java/JasperReports/EmployeeReport/web/WEB-INF/reports/employeeReport.jrxml

I have used following statement to specify my source and destination files.

String source = "WEB-INF/reports/employeeReport.jrxml";
String destination = "WEB-INF/reports/employeeReport.pdf";

But it's not working and shows FileNotFoundException. Please Help.
Thanks.

Comments
good to use code tags!
A rarity, new poster using Code tags in the first post itself.

We will first need to find out your current working directory. For that using the File class, in your JSP page create a new file as :-

File f = new File("temp.txt");
out.println("New file created : " + f.createNewFile());
out.println("Absolute path of File : " + f.getAbsolutePath() );

The second statement will give you the absolute path where the file was created, note that path excluding the "temp.txt". All your paths should be relative to the directory in which temp.txt was created.

Of course there could be other ways but I do not have any info on Glassfish + NetBeans combo.

Hi,

Thanks for the reply and it's very helpful.

It is showing it's current directory as

C:/Program Files/glassfish-v2ur2/domains/domain1/config/..

I realized what is the problem here.

But to generate report I have to specify the path here and my report file is located at

D:/Programs/Java/JasperReports/EmployeeReport/web/WEB-INF/reports/employeeReport.jrxml

So can you suggest me a good tutorial where I learn to set relative path coz I found it little bit confusing.

Thanks.

Relative paths are quite easy. Now you know your working directory is :-

C:/Program Files/glassfish-v2ur2/domains/domain1/config/

But you want the file located at :-

D:/Programs/Java/JasperReports/EmployeeReport/web/WEB-INF/reports/employeeReport.jrxml

One thing to remember in relative paths is ".." indicates the parent directory.

Try using the following path to access your file:-

../../../../Java/JasperReports/EmployeeReport/web/WEB-INF/reports/employeeReport.jrxml

But you might want to check if theres a better way to get it to work.

This article has been dead for over six months. Start a new discussion instead.