How do I resolve LinkageError with JasperReports (6. *)?

eg. we got:

net.sf.jasperreports.engine.JRException: ...
Caused by: net.sf.jasperreports.engine.fill.JRExpressionEvalException: 
  Error evaluating expression for source text: 
    $P{REPORT_SCRIPTLET}.setTestRaw_LogOn_TstMsgOn(true, true)
Caused by: java.lang.LinkageError: loader constraint violation: loader 
  (instance of java/net/FactoryURLClassLoader) previously initiated loading 
  for a different type with name "org/slf4j/Logger"

      

works in Eclipse (Kepler) Preview with JR plugin v6.1.0 but not other Eclipse working with 5.5.1.final

Obviously we are using our own path-building script which itself uses the slf4j api for logging.

It seems to contradict another version of the same class (for the same basic class loading isolation).

+3


source to share


3 answers


(Whoo ... finally at least an acceptable workaround for this apparently groovy class loading problem has been found)

We have created a very simple helper reporthlprep.jrxml

that itself

  • uses the specified script

    • or will use / call any other java class, you will have problems with
  • set the value language=java

    • (other sites recommend switching from language=groovy

      to java

      to get rid of the above error, but this is often not an option)

(It should now work fine in Preview

)

Every time you experience this error (it might be accidental, as the loading of the classes might be correct, depending on what you did previously in your IDE), we can now do the following:



  • open up hlprep.jrxml

    • at best with Open with ... JasperReports Preview

      (so you don't need to explicitly open the preview in further steps)
  • restart your Eclipse

    • it must remember your open files after reboot, otherwise you need to open the assistant report after reboot.
  • select / browse hlprep.jrxml

    • the class is now loaded correctly (caused by the java context)
  • select / view (already open) other report (s) that are not running

It should now work fine even after changes, but may crash if you open / close new ones again . (since classes can be reworked or the isolation magic of the groovy classloader is loaded differently)

our environment

  • Eclipse neon 3
    • uses groovy 2.4.5 internally
    • starts with JDK 1.8.0_121
  • Jaspersoft Studio 6.3.2 final
    • we have server 6.3.0, but full support for Neon was added in 6.3.1, so we took the latest version of the 6.3.x patch
    • we had issues before new studio versions didn't work with old servers, so we are more careful with updates here.
  • may be out of date:
    • it was enough just to depend on the slf4j api (1.7.12 in our case) in pom.xml

    • we both provided jasper libraries added to the project : Jaspersoft Server Library

      ,JasperReports Library Dependencies

    • we also depend on the server functionality, so we have jasperreports-6.3.0.jar

      in pom.xml

      and some (and not via some public Maven repo) server jars as User Library

      for the project (which we copied from the server)
    • no groovy link in pom.xml

0


source


I have the same problem and I solved it by adding these Jars in Build to my project:

  • slf4j-api-1.7.12.jar
  • slf4j-log4j12-1.7.12.jar
  • SLF4J-simple 1.7.12.jar

and add also JasperReports Library

, and JasperReports Library Dependencies

the draft

with these steps



  • Right click in the project
  • Build Cat> Customize Build Path
  • go to libraries and add jars with Add External JARs

  • Add JasperReport Library and JasperReport Library Dependencies with Add Library

  • and then go to Order and Export

    and check the new added libraries and jars and click ok

you get a result like this:

enter image description here

+3


source


The simplest solution for us (after some trying with libraries and tweaking) was to switch back to the Eclipse db file backup with the Jasper v5.5.1.final plugin (where we still had a copy for all developers).

There was no way to "go back" through the Eclipse installation history because either our main update site only points to the latest, or there may not be an old update site for 5.5.1.final at all. (we haven't researched yet)

(btw: it might be safe to disable automatic updates in Eclipse to avoid such surprises)

Environment Information:

(... to likely reasons for those who might find other working solutions.)

For us, this is using org.slf4j.Logger (with slf4j-api-1.7.5.jar and slf4j-simple-1.7.5.jar in the build path or with deletion - doesn't matter ... just closing and reopening all reports after changes without restarting Eclipse)

Starting with Eclipse option eclipse.ini jvm -verbose:class

shows that the conflict may be associated with this other loaded class (if it is loaded (possibly, jasper editor preview itself) eclipse/plugins/org.slf4j.api_1.7.2.v20121108-1250.jar

)

I suppose Jasper is using SLF4J since v6 and does not isolate the class loading / libs for individual classes with a separate classloader from its own versions of the classes (or those provided by the Eclipse installation) and therefore such binding errors might occur (e.g. How to deal with LinkageErrors in Java?. ).

There is already a known bug for this since 6.0.4 (where I added this information), but it is clearly not resolved: http://community.jaspersoft.com/jaspersoft-studio/issues/3831#comment-818386

+1


source







All Articles