We are making a Java application that will be deployed on web server to
generate a PDF of a Jasper report. We are having trouble getting the correct
path for the sourceFileName for runReportToPdfFile.
If we hard code an absolute path to a file on the local machine it works as
expected. For example:
C:\\Users\\username\\workspace\\projectname\\WebContent\\
If we hard code an absolute URL runReportToPdfFile seems to convert
http://to http:/ and we get a JRException. For example:
http://localhost:8080/projectname/
>> Becomes "http:\localhost:8080\projectname\"
net.sf.jasperreports.engine.JRException: java.io.FileNotFoundException: ...
To test paths we tried creating a file a new File() and using
getAbsolutePath() to find it's location, hoping we would be able to figure
out the relative path. It appears to be looking in the root of the eclipse
folder, whereas the example I found on the internet appears to be looking in
the project root (http://www.java2s.com/Code/JavaAPI/java.io/FilegetPath.htm).
For example:
File f1 = new File("all_contracts.jasper");
System.out.println(f1.getAbsolutePath());
>> Our outputs "C:\eclipse\all_contracts.jasper"
File f1 = new File("MainClass.java");
System.out.println(f1.getAbsolutePath());
>> Java2s' outputs "C:\Java_Dev\workspace\cal\MainClass.java"
What we plan to do is to get the project's base path at runtime so that we
can make all of our paths relative to it, but we cannot figure out how to do
this. Is there a method or constant we could use? Is there a way to make
runReportToPdfFile accept http URLs? Will deploying on a real server fix
this problem?
If that is not the best solution, we are open to suggestions. What we would
like to achieve is to be able to deploy this project on several servers
without needing to change the code. We are testing the application through
Eclipse Europa on Tomcat v6.0 under Windows Vista 32-bit.
-Scot
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
jasperreports-questions mailing list
jasperreports-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jasperreports-questions