0

our web application uses JasperReports 3.0.0 to generate PDFs, I started moving our IDE version (Eclipse) from Mars to Oxygen, which is based on JDK 8. Everything goes fine, since we run our JUnit tests which simulates creation of reports..

Configured JDK inside Eclipse for our project is set on JDK 7.x, while OS (Ubuntu 16.04 LTS) is set up for JDK 8. If I run my test, it returns me the exception I attached below:

java.lang.UnsupportedClassVersionError: RicevutaNoPrenotazione_1504035333064_598616 : Unsupported major.minor version 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at net.sf.jasperreports.engine.util.JRClassLoader.loadClass(JRClassLoader.java:342)
at net.sf.jasperreports.engine.util.JRClassLoader.loadClassFromBytes(JRClassLoader.java:243)
at net.sf.jasperreports.engine.design.JRAbstractJavaCompiler.loadEvaluator(JRAbstractJavaCompiler.java:92)
at net.sf.jasperreports.engine.design.JRAbstractCompiler.loadEvaluator(JRAbstractCompiler.java:320)
at net.sf.jasperreports.engine.JasperCompileManager.loadEvaluator(JasperCompileManager.java:244)
at net.sf.jasperreports.engine.fill.JRFillDataset.createCalculator(JRFillDataset.java:411)
at net.sf.jasperreports.engine.fill.JRBaseFiller.<init>(JRBaseFiller.java:405)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:77)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:59)
at net.sf.jasperreports.engine.fill.JRFiller.createFiller(JRFiller.java:147)
at net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:83)
at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:601)
at it.loginet.petrol.infrastructure.jasper.PetrolReport.fillTemplateWithParameters(PetrolReport.java:171)
at it.loginet.petrol.infrastructure.jasper.PetrolReport.createJasperPrint(PetrolReport.java:166)
at it.loginet.petrol.infrastructure.jasper.PetrolReport.exportReportToXml(PetrolReport.java:161)
at it.loginet.petrol.application.prenotazione.StampaNoPrenotazione.printAsXml(StampaNoPrenotazione.java:60)
at it.loginet.petrol.application.prenotazione.StampaNoPrenotazioneOnlineTest.verifyGeneratedXml(StampaNoPrenotazioneOnlineTest.java:71)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

It seems JasperReports takes the wrong JDK (8) to compile our reports, although we set the project to run under JDK 7. Actually, if I run my JasperReports tests setting up JDK 7 on the OS, everything goes fine.

What's the configuration I'm missing on our machine?

Hope I explained our situation clearly, feel free to ask any question :) Thanks

leodali
  • 301
  • 3
  • 16
  • With your application (Java 7 based) you can use this old library, but looks like you are using *jasper* files compiled with JasperReports cooperating with Java 8 (*Unsupported major.minor version 52.0*) – Alex K Aug 30 '17 at 12:17
  • Are you compiling templates or using *jasper* files at your failed tests? – Alex K Aug 30 '17 at 12:19
  • @AlexK thanks for your answer! We always fill .jrxml templates with parameters, actually we don't use .jasper files. You can take a look at the last "domain" call in the stack, 'PetrolReport.fillTemplateWithParameters(PetrolReport.java:171)' .. – leodali Aug 30 '17 at 20:22
  • @Yannick I took a look at that question, I can't figure out how to setup Eclipse and dev environment. What we did is change Eclipse version from Mars (4.5) to Oxygen (4.7)..Oxygen need JDK 8 to start, so we defined the JAVA_HOME accordingly. If we configure Java compiler compliance to 1.7, we still got the Exception..at this time, that answer doesn't solve our problem. – leodali Aug 31 '17 at 08:15
  • @leodali Okay, I've posted an answer with my guess – Yannick Aug 31 '17 at 09:10

1 Answers1

1

As you already said, it seems like that your project is running with Java 7 and your reports are compiled with JDK 8. (Maybe it uses your JAVA_HOME by default, which you said is set to JDK 8)

Please check your preferences in Jaspersoft Studio and set it to 1.7

Window -> Preferences

Jaspersoft Studio preferences

Or you can look up which Java version is used here:

Help -> Installation Details -> Configuration

Jaspersoft Studio installation details

Yannick
  • 813
  • 8
  • 17
  • JasperReports were designed using iReport 5.5.0, which has not settings you posted. I'm sure the best thing to do would be upgrading either JasperReports library and JasperReports designer (aka JasperSoft Studio) to the latest version, but I really would like to understand what's the wrong setting that makes me JUnit test fails with UnsupportedClassVersionError.. – leodali Sep 01 '17 at 07:02
  • I've also used `iReport` in the begin and switched to `Jaspersoft Studio` while upgrading to the newest `Jasperreports` version (I think you'll like `Jaspersoft Studio`, because it uses the Eclipse framework). There's only one reason why an `UnsupportedClassVersionError` occurs: You are calling a *JDK 8* compiled jar from a *Java 7 runtime environment*, but it would be interesting to know which one is the problem. – Yannick Sep 01 '17 at 07:21
  • [...] *calling a JDK 8 compiled class out of a JRE 7* [...] – Yannick Sep 01 '17 at 07:37
  • Sounds really weird because what I changed it's just the Eclipse IDE version (from Mars to Oxygen), and I configured Oxygen to run with same JDK 7 I used with Mars; on Eclipse Mars everything goes fine :) what seems to be compiled with JDK 8 is resulting report filled during JUnit test (RicevutaNoPrenotazione_*****), but how? That's not clear.. – leodali Sep 01 '17 at 15:50