2006 IR Open Discussion Posted August 20, 2006 Share Posted August 20, 2006 By: Enrico Colombo - carvermotion Jasper files deployment 2002-04-12 03:06 Hi everybody! Is there anybody among you who can help me to find a tasteful solution about deploing my '.jasper' files with my application '.jar' archive? Any suggestion is welcome! Thanks a lot, carvermotion By: Samanth Athrey - samanth_athrey RE: Jasper files deployment 2002-04-12 03:09 Hi, Could you be more elaborate on what you want to do? sva By: Ryan Johnson - delscovich RE: Jasper files deployment 2002-04-15 22:05 Samanth, I just use a package tree to store all the .jasper files, along with any scriptlets I use. The directory /com/company/reports/ would contain the .jasper file (say report.jasper) and the scriplet class (maybe com.company.reports.Scriptlet) class. Then, I jar the whole tree starting at /com. To use the scriptlet in the program, no further work is necessary because it gets loaded with the jar. The .jasper file can be accessed as an InputStream using ClassLoader.getSystemResourceAsStream("com/company/reports/report.jasper"); From there, the InputStream can be passed directly to JasperManager as desired. Good Luck, Ryan By: Keith Berman - bobbassen RE: Jasper files deployment - locating files 2002-08-21 13:23 Will this create the .jrprint file in the same directory as the .jasper file? I will be creating my PDF files on a Unix box so I need to know where to find them after I compile and then create the PDF. I would like to store my .jasper files in one directory and then store my PDF files in another. Is that possible? By: Teodor Danciu - teodord RE: Jasper files deployment - locating files 2002-08-22 00:46 Hi, I have maybe an useful hint for all of you trying to load .jasper or .jrprint files in order to fill or view reports. You can use the loadObjectFromLocation(String location) method of the JRLoader class. Please do not try to use those loadReport() or loadPrint() etc methods of this class because they will be removed in the 0.3.4 version. Only those loadObjectXXX() methods will remain. No back to this loadObjectFromLocation method: It first tries to interpret the supplied String as an URL. If it is not a URL, then it tries to load an object from the file on disk represented by the String. If there is no such file on disk it tries to load the object from the same location, but in the Classpath (with getResource()). You, see? You can place the .jasper files in a JAR file and you can load them with this method that will finally search the Classpath. As for the second issue, the answer is YES, you can specify the location of the .jrprint file, if you don't want to have the default behavior that places this file in the same directory with the .jasper file. There are two methods in JasperFillManager: public static void fillReportToFile( JasperReport jasperReport, String destFileName, Map parameters, Connection conn ) throws JRException public static void fillReportToFile( JasperReport jasperReport, String destFileName, Map parameters, JRDataSource jrDataSource ) throws JRException All you have to do is to load an JasperReport object from the .jasper file as I have previously explained and then you pass it to those filling methods along with the desired name of the output .jrprint file. There are similar methods in the JasperPrintManager that let you control the location for the generated PDF file. You could even load the .jasper file and directly generate the PDF file in the desired location without creating a .jrprint file on disk. This is why we have JasperRunManager. Feel free to "invent" you own way of dealing with loading, filling, etc, if you don't find the proper method in the managers. You can check the code and you'll see that it is not difficult to combine those basic functionalities of the library, like those manager classes do in order to make the whole library more user friendly. I hope this helps. Teodor By: Keith Berman - bobbassen RE: Jasper files deployment 2002-08-23 08:35 Thanks for the reply. I am able to specify a path to find my jasper files (com/......l/reports/p2/" + "P2eng.jasper" using the JRLoader.loadObjectFromLocation. The problem I am having now is trying to write that file to specific location. The JasperFillManager.fillReportToFile(newFilename, jrprintFileName, parameters, ds) method I am using takes a File Name (jrprintFileName) as a parameter for the destination. But if I pass in a pathname with that I get a "java.io.FileNotFoundException". I think the problem is that the printReportToPdfFile method uses the new FileOutputStream(destFileName) method which expects a name, not a path. Therefore, do I need to write something specific to specify the destination directory's instead of the file name. The same problem above exists when I want to specify the destination directory for the pdf. By: Teodor Danciu - teodord RE: Jasper files deployment 2002-08-27 00:01 Hi, Feel free to create your own methods that receive a path instead of an absolute file name, for the output file. This shouldn't be hard to do using the basic functionality offered by the library (no more than 5 to 10 lines of code). Good luck! Teodor By: Keith Berman - bobbassen RE: Jasper files deployment - jar file 2002-08-28 11:17 Thanks, was a problem with the jar. By: Anil kumar - togopi RE: Jasper files deployment 2003-03-05 09:38 Hi, I had those .jasper files at my classes directory and it works fine in my IDE while testing, but when I deployed it on to the JBoss in a EJB jar, packing those .jasper files at root path of the jar. it fails to load jaspers and gives following warning.. ************************************************************************* * WARNING: Failure using Thread.currentThread().getContextClassLoader() * * in JRLoader class. Using JRLoader.class.getClassLoader() instead. * ************************************************************************* dori.jasper.engine.JRException: Could not load object from location : com/metapack/dace/upig/manifest/utils/parcelManifest.jasper at dori.jasper.engine.util.JRLoader.loadObjectFromLocation(JRLoader.java:234) It failseven when I tried putting those into some classes directory and giving relative path. And also tried putting in classpath, placing in libext.. running out of ideas. I don't want to give a relative path. Any thoughts or help is highly appreciated. Thanks, Anil. By: Anil kumar - togopi RE: Jasper files deployment 2003-03-05 10:12 Sorry, I meant I don't want to give a absolute path. By: Anil kumar - togopi RE: Jasper files deployment 2003-03-05 10:23 Sorry, I meant I don't want to give a absolute path. By: Teodor Danciu - teodord RE: Jasper files deployment 2003-05-10 04:11 Hi, Could this be a problem with the name of the .jasper file not being spelled correctly? Check the case in the file name. I hope this helps. Teodor By: Keith Berman - bobbassen RE: Jasper files deployment - jar files 2002-08-27 08:08 Thanks Teodor, I may do that. For now, I am using the relative path - "/jasperreports/reports/" to write my pdf to and that seems to work. I am having a problem reading the .jasper file from a jar. I have a reports.jar with the classes and jasper files in them. I am using this method in my Fill code: JasperReport newFilename = (JasperReport)JRLoader.loadObjectFromLocation(jasperFileName); When I run the fill method, I get the following error: >2 2002/08/27-09:29:29 Jasper Exception: Error loading object from URL : jar:file:/C:/fch/lib/reports.jar!/com/exp/reports/p2/P2eng.jasper >2 2002/08/27-09:29:29 Exception is: java.util.zip.ZipException: invalid literal/length code I have the jasper stored in the jar with this path: com/exp/.../P2eng.jasper. Not sure why it can't find it since I have no problems using the classes in the jar. Thanks for any help! By: Teodor Danciu - teodord RE: Jasper files deployment - jar files 2002-08-27 08:18 Hi, Not sure, but it seems that the JAR file is somehow corrupted. Try to unzip it to see if its content is still valid. I hope this helps. Teodor By: Michael Mai - mmai RE: Jasper files deployment - jar files 2003-10-28 17:42 Hi, I used the same technic(jar) to load jasper file, it works great at window environment, however, when I deployed it to Unix and I got fileNotFoundException. I did put jar file to lib dir and add path to classpath. Any idea? Thanks, Michael Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now