javaeclipseexceptionjasper-reportsillegalaccessexception

IllegalAccessException when loading .jrxml


I'm trying to fix a bug that show up when trying to export a jasper report as a pdf, but when loading a .jrxml file using the JRXmlLoader, the code throws this exception:

Caused by: java.lang.IllegalAccessException: Class org.openide.util.WeakListenerImpl$ProxyListener can not access a member of class org.openide.filesystems.$Proxy0 with modifiers "public"
    at sun.reflect.Reflection.ensureMemberAccess(Unknown Source)
    at java.lang.reflect.AccessibleObject.slowCheckMemberAccess(Unknown Source)
    at java.lang.reflect.AccessibleObject.checkAccess(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.openide.util.WeakListenerImpl$ProxyListener.<init>(WeakListenerImpl.java:413)
    ... 100 more

This is the code that seems to cause that execption :

    JasperDesign jasperDesign = JRXmlLoader.load("C:/jrxmls/myreport.jrxml"); //< this line
    JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
    jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, resultSetDataSource);

Since it is not my code, and since I don't really know how to work using jasper, I apologize in advance for not being able to provide more context to this issue.

I've added multiple org.openide- to my buildpath, because I had a a ton of "ClassNotFoundException", maybe this is where the problem came from ?

I've read somewhere that the problem might come from jasperreport compatibility issues with the JDK 8, but the weird thing is that the code works when running from Eclipse, the exception is only thrown when running as a runnable jar file. This program is not young, it might have 2 years, and until now, the program ran perfectly (as I heard).

EDIT : Okay, so, I tried to run the program using version 1.7 of the jre. Unfortunatly, since it depends on other programs running on 1.8, I can't test this solution.


Solution

  • Ok so, I found out what the problem was. I thought it was some missing jars problems, but it was actually a completely different error. The first exception we got was this one :

    org.xml.sax.SAXParseException; lineNumber: 12; columnNumber: 16; Error at line 12 char 16: null
    

    when looking at the stacktrace, it showed this :

    Caused by: java.lang.ClassNotFoundException: org.openide.util.Lookup
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 74 more
    

    That's why I thought that the program was missing some dependencies.

    But the problem was that in the .jrxml file, we added a <queryString>...</queryString> that was used ONLY when testing the document, and within the code, we wanted to replace this query by another one, which led to this exception being thrown.

    By removing the whole <queryString>...</queryString>, we were able to solve to problem.

    Thanks for the input, I appreciate.