Exception when compiling JasperReport with javascript language
Asked Answered
E

1

6

I'm trying to compile a JasperDesign to create a report programmatically. Since I need to include a Conditional Style in Javascript, I set the JasperDesign language accordingly:

val jasperDesign = new JasperDesign
jasperDesign.setLanguage("javascript")

Note that I'm using Scala 2.11 on Java 8, running on Play for Scala 2.5

Since JasperReports 6.4.3 (the version I'm using) has a dependency on rhino 1.7.6, I added it to the classpath:

libraryDependencies += "org.mozilla" % "rhino" % "1.7.6"

The problem is that whenever I compile the JasperDesign I get an exception. This happens even when I don't include a Javascript Conditional Style:

java.lang.NoSuchMethodError: org.mozilla.javascript.ContextFactory.enterContext()Lorg/mozilla/javascript/Context; at net.sf.jasperreports.compilers.JavaScriptClassCompiler.compileUnits(JavaScriptClassCompiler.java:124) at net.sf.jasperreports.engine.design.JRAbstractCompiler.compileReport(JRAbstractCompiler.java:203) at net.sf.jasperreports.engine.JasperCompileManager.compile(JasperCompileManager.java:357) at net.sf.jasperreports.engine.JasperCompileManager.compileToStream(JasperCompileManager.java:326) at net.sf.jasperreports.engine.JasperCompileManager.compileReportToStream(JasperCompileManager.java:599)

If I remove jasperDesign.setLanguage("javascript") I have no compilation errors. What is missing here? Is there a conflict between Nashorn and Rhino?

Education answered 15/7, 2018 at 12:36 Comment(3)
Sounds like you're looking for a version of Rhino at 1.6 or older somewhere on the classpath. ContextFactory.enterContext() was added with 1.7R1.Shinleaf
Play is using a Rhino based Trireme JavaScript engine (according to here), that's probably creating the conflict, I tried adding to sbt dependencyOverrides ++= Set("org.mozilla" % "rhino" % "1.7.6") and the problem persists.Education
My solution was to take the rhino 1.7.6 jar and manually put it in the application lib folder. Play loaded it from there with no issues.Education
E
1

My solution was to take the rhino 1.7.6 jar and manually put it in the application lib folder. Play loaded it from there with no issues.

Education answered 21/7, 2018 at 16:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.