Results 1 to 15 of 15
  1. #1
    sirdeaz is offline Member
    Join Date
    Oct 2010
    Posts
    8
    Rep Power
    0

    Default 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

  2. #2
    mine0926 is offline Senior Member
    Join Date
    Apr 2010
    Location
    Philippines
    Posts
    580
    Rep Power
    5

    Default

    Are you sure you input a valid path? I think the compiler cannot find the path that you input.

  3. #3
    sirdeaz is offline Member
    Join Date
    Oct 2010
    Posts
    8
    Rep Power
    0

    Default

    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?

  4. #4
    mine0926 is offline Senior Member
    Join Date
    Apr 2010
    Location
    Philippines
    Posts
    580
    Rep Power
    5

    Default

    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);
        ....

  5. #5
    sirdeaz is offline Member
    Join Date
    Oct 2010
    Posts
    8
    Rep Power
    0

    Default

    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.

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,044
    Rep Power
    20

    Default

    It's concatenated something together to get this:
    META-INFpersistence.xml

    Have you missed a slash somewhere?

  7. #7
    sirdeaz is offline Member
    Join Date
    Oct 2010
    Posts
    8
    Rep Power
    0

    Default

    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.

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,044
    Rep Power
    20

    Default

    Something somewhere is missing a slash.
    Hence the META-INFpersistence.xml.

  9. #9
    sirdeaz is offline Member
    Join Date
    Oct 2010
    Posts
    8
    Rep Power
    0

    Default

    Thanks again for your help.

    Something must have gone wrong during the initial pasting of the stack dump.

    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)
    The backslash isn't missing. ;)

  10. #10
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,044
    Rep Power
    20

    Default

    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?

  11. #11
    sirdeaz is offline Member
    Join Date
    Oct 2010
    Posts
    8
    Rep Power
    0

    Default

    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).

  12. #12
    mine0926 is offline Senior Member
    Join Date
    Apr 2010
    Location
    Philippines
    Posts
    580
    Rep Power
    5

    Default

    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

  13. #13
    sirdeaz is offline Member
    Join Date
    Oct 2010
    Posts
    8
    Rep Power
    0

    Default

    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.

  14. #14
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,044
    Rep Power
    20

    Default

    Oh right, so it was a bug in the jar then?
    Always nice to know.
    Thanks for passing that on.

  15. #15
    sirdeaz is offline Member
    Join Date
    Oct 2010
    Posts
    8
    Rep Power
    0

Similar Threads

  1. Java Based Application to Map Network Drive
    By Wraithier in forum New To Java
    Replies: 15
    Last Post: 05-24-2012, 11:09 AM
  2. Open Source web based Java Chat application
    By anitha2324 in forum Advanced Java
    Replies: 4
    Last Post: 07-01-2009, 08:55 AM
  3. Replies: 2
    Last Post: 04-06-2009, 05:52 PM
  4. Java based Web Application architecture
    By AmmarKhalid in forum New To Java
    Replies: 1
    Last Post: 11-05-2008, 08:20 AM
  5. Replies: 0
    Last Post: 03-25-2008, 12:45 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •