Results 1 to 15 of 15
- 10-10-2010, 10:34 AM #1
Member
- Join Date
- Oct 2010
- Posts
- 8
- Rep Power
- 0
Jasperreports and a jpa based java se application
Hi,
I'm working on an standard java desktop application which uses jpa (eclipselink 2.0.0) in nb 6.9.0. It's working like a charm. It's fetching data and displaying it by using jfreechart.
If I try to create a report, it throws an error stating that it can't find the persistence.xml file even though all the other jpa functionality is working.
The runtime error + code used to create the report is included:
Java Code:java.lang.RuntimeException: java.lang.RuntimeException: Unable to load persistence.xml : META-INFpersistence.xml (The system cannot find the path specified) at org.eclipse.persistence.internal.jpa.modelgen.CanonicalModelProcessor.process(CanonicalModelProcessor.java:366) at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:624) at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:553) at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:698) at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:981) at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:727) at com.sun.tools.javac.main.Main.compile(Main.java:353) at com.sun.tools.javac.main.Main.compile(Main.java:279) at com.sun.tools.javac.main.Main.compile(Main.java:270) at com.sun.tools.javac.Main.compile(Main.java:69) at com.sun.tools.javac.Main.main(Main.java:54) Caused by: java.lang.RuntimeException: Unable to load persistence.xml : META-INFpersistence.xml (The system cannot find the path specified) at org.eclipse.persistence.internal.jpa.modelgen.objects.PersistenceUnitReader.getInputStream(PersistenceUnitReader.java:105) at org.eclipse.persistence.internal.jpa.modelgen.objects.PersistenceUnitReader.initPersistenceUnits(PersistenceUnitReader.java:160) at org.eclipse.persistence.internal.jpa.modelgen.objects.PersistenceUnitReader.<init>(PersistenceUnitReader.java:63) at org.eclipse.persistence.internal.jpa.modelgen.CanonicalModelProcessor.process(CanonicalModelProcessor.java:329) ... 10 more at net.sf.jasperreports.engine.design.JRAbstractCompiler.compileReport(JRAbstractCompiler.java:191) at net.sf.jasperreports.engine.JasperCompileManager.compileReport(JasperCompileManager.java:215) at net.sf.jasperreports.engine.JasperCompileManager.compileReport(JasperCompileManager.java:201) at be.carglass.warehouseoverview.reporting.ReportManager.generateChecklist(ReportManager.java:58) at be.carglass.warehouseoverview.gui.pie.DefaultPieChartPanel$1$1.execute(DefaultPieChartPanel.java:52) at be.carglass.warehouseoverview.gui.MainFrame$1.doInBackground(MainFrame.java:139) at be.carglass.warehouseoverview.gui.MainFrame$1.doInBackground(MainFrame.java:135) at javax.swing.SwingWorker$1.call(SwingWorker.java:277) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) at java.util.concurrent.FutureTask.run(FutureTask.java:138) at javax.swing.SwingWorker.run(SwingWorker.java:316) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:619) code to create the report: public ReportResult generateReportGermany(Warehouse warehouse) throws Exception { List<ChecklistRecord> records = ChecklistRecord.findAllByWarehouseAndRouteType(warehouse, CheckListType.getCheckListTypeForGermany()); return generateReport("Germany", warehouse, CHECKLIST_DATASOURCE_GERMANY, new JRBeanCollectionDataSource(records)); } private ReportResult generateReport(String country, Warehouse warehouse, String report, JRDataSource ds) throws Exception { String tempFile = getTempFileName(); HashMap<String, String> parameters = new HashMap<String, String>(); parameters.put("country", translate(country)); // compile JasperReport jasperReport = JasperCompileManager.compileReport(ClassLoader.getSystemResourceAsStream(report)); // fill it JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, ds); // export to pdf JasperExportManager.exportReportToPdfFile(jasperPrint, tempFile); return new ReportResult(tempFile, warehouse); }
How can I resolve this issue?
Regards,
Frederik
- 10-11-2010, 09:35 AM #2
Senior Member
- Join Date
- Apr 2010
- Location
- Philippines
- Posts
- 580
- Rep Power
- 4
Are you sure you input a valid path? I think the compiler cannot find the path that you input.
- 10-11-2010, 09:46 AM #3
Member
- Join Date
- Oct 2010
- Posts
- 8
- Rep Power
- 0
Thanks a lot for your reply.
Which path are you referring to?
It seems that it can't find the persistence.xml file, but the weird bit is that all the other jpa functionality is working. It's complaining when I try to build the report.
There's a persistence.xml in the following dirs (i'm using netbeans):
\WarehouseOverview\build\classes\META-INF
\WarehouseOverview\src\META-INF
The code to generate the report only works when I add an additional META-INF to:
\WarehouseOverview\META-INF
I would like to point out that all the code is working by using the persistence.xml located in \WarehouseOverview\build\classes\META-INF, except for the jasperreport bit.
Why can't the reporting bit use the same persistence.xml file as the rest of the application?
- 10-11-2010, 09:51 AM #4
Senior Member
- Join Date
- Apr 2010
- Location
- Philippines
- Posts
- 580
- Rep Power
- 4
Is persistence.xml is the name or your file(the report you created)? The file path of your report should be complete.
this might not like your code, I just copy this from my code.
Java Code:String file = [b]"D:\\my folder\\persistence.xml"[/b] JasperReport report = JasperCompileManager.compileReport(file); JasperPrint print = JasperFillManager.fillReport(report, param, conn); JRViewer viewer = new JRViewer(print); ....
- 10-11-2010, 09:57 AM #5
Member
- Join Date
- Oct 2010
- Posts
- 8
- Rep Power
- 0
Persistence.xml is the file responsible for the jpa setup.
The file needed in JasperCompileManager.compileReport is the report layout defined in a .jrxml file.
It can successfully locate it. It's stored at be/carglass/warehouseoverview/reports/checklistDataSource.jrxml.
- 10-11-2010, 10:03 AM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
It's concatenated something together to get this:
META-INFpersistence.xml
Have you missed a slash somewhere?
- 10-11-2010, 10:19 AM #7
Member
- Join Date
- Oct 2010
- Posts
- 8
- Rep Power
- 0
I haven't setup a reference to the persistence.xml. This is done automatically by eclipselink (jpa framework).
A part of the application loads data from the database and displays it by using jfreechart. This part works fine (it's able to locate the persistence.xml file).
It's just the jasperreport bit that's having issues with locating the persistence.xml file even though it's located in the classpath.
- 10-11-2010, 10:45 AM #8
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Something somewhere is missing a slash.
Hence the META-INFpersistence.xml.
- 10-11-2010, 11:13 AM #9
Member
- Join Date
- Oct 2010
- Posts
- 8
- Rep Power
- 0
Thanks again for your help.
Something must have gone wrong during the initial pasting of the stack dump.
The backslash isn't missing. ;)Java Code:11-okt-2010 11:54:29 be.carglass.warehouseoverview.gui.GuiRefreshManager$MyThreadPool afterExecute SEVERE: null java.util.concurrent.ExecutionException: net.sf.jasperreports.engine.JRException: Errors were encountered when compiling report expressions class file: Note: Creating the metadata factory ... Note: Building metadata class for round element: ReportExpressionsDemo_1286790868831_667913 error: java.lang.RuntimeException: Unable to load persistence.xml : META-INF\persistence.xml (The system cannot find the path specified) Note: org.eclipse.persistence.internal.jpa.modelgen.objects.PersistenceUnitReader.getInputStream(PersistenceUnitReader.java:105) Note: org.eclipse.persistence.internal.jpa.modelgen.objects.PersistenceUnitReader.initPersistenceUnits(PersistenceUnitReader.java:160) Note: org.eclipse.persistence.internal.jpa.modelgen.objects.PersistenceUnitReader.<init>(PersistenceUnitReader.java:63) Note: org.eclipse.persistence.internal.jpa.modelgen.CanonicalModelProcessor.process(CanonicalModelProcessor.java:329) Note: com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:624) Note: com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:553) Note: com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:698) Note: com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:981) Note: com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:727) Note: com.sun.tools.javac.main.Main.compile(Main.java:353) Note: com.sun.tools.javac.main.Main.compile(Main.java:279) Note: com.sun.tools.javac.main.Main.compile(Main.java:270) Note: com.sun.tools.javac.Main.compile(Main.java:69) Note: com.sun.tools.javac.Main.main(Main.java:54)
- 10-11-2010, 11:19 AM #10
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Oh right.
That looks better.
:)
Pity it's so deep down.
Be nice to know exactly where it thinks it's looking.
I don't expect you can debug down to there and see what it's doing in that eclipse code?
By the way, is this when running in Eclipse or when deployed?
- 10-11-2010, 11:45 AM #11
Member
- Join Date
- Oct 2010
- Posts
- 8
- Rep Power
- 0
It's running fine in netbeans when I add an additional META-INF (containing the persistence.xml file) in \WarehouseOverview\META-INF.
This causes issues when I deploy the application as a jar file. In the jar file the meta-inf is located at WarehouseOverview-dist.jar\META-INF.
I can't understand why part of the program is locating the META-INF\persistence.xml file (code used to do all the database related fetching) and the other part is not (jasperreports).
- 10-12-2010, 06:34 AM #12
Senior Member
- Join Date
- Apr 2010
- Location
- Philippines
- Posts
- 580
- Rep Power
- 4
Lets see what will be the output if you use System.out.println in report and tempFile.
Java Code:private ReportResult generateReport(String country, Warehouse warehouse, String report, JRDataSource ds) throws Exception { String tempFile = getTempFileName(); [b] System.out.println("Report: " + report); System.out.println("Temp : " + tempFile); [/b] HashMap<String, String> parameters = new HashMap<String, String>(); parameters.put("country", translate(country)); // compile JasperReport jasperReport = JasperCompileManager.compileReport(ClassLoader.getSystemResourceAsStream(report)); // fill it
- 10-12-2010, 11:02 AM #13
Member
- Join Date
- Oct 2010
- Posts
- 8
- Rep Power
- 0
I've been able to resolve the issue by updating eclipselink to its latest version!
I would like to thank everyone for their polite and helpful replies.
- 10-12-2010, 11:08 AM #14
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Oh right, so it was a bug in the jar then?
Always nice to know.
Thanks for passing that on.
- 10-12-2010, 07:16 PM #15
Member
- Join Date
- Oct 2010
- Posts
- 8
- Rep Power
- 0
Similar Threads
-
Java Based Application to Map Network Drive
By Wraithier in forum New To JavaReplies: 15Last Post: 05-24-2012, 11:09 AM -
Open Source web based Java Chat application
By anitha2324 in forum Advanced JavaReplies: 4Last Post: 07-01-2009, 08:55 AM -
How to connect to Window based file server from a Java Application
By anupbkk in forum Advanced JavaReplies: 2Last Post: 04-06-2009, 05:52 PM -
Java based Web Application architecture
By AmmarKhalid in forum New To JavaReplies: 1Last Post: 11-05-2008, 08:20 AM -
display images in a Web Application based on java/jsp
By mnsse in forum Advanced JavaReplies: 0Last Post: 03-25-2008, 12:45 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks