5

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?

Alex K
  • 22,315
  • 19
  • 108
  • 236
ps0604
  • 1,227
  • 23
  • 133
  • 330
  • 1
    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. – df778899 Jul 17 '18 at 19:18
  • Play is using a Rhino based Trireme JavaScript engine (according to [here](https://stackoverflow.com/questions/31491931/warning-node-js-detection-failed-sbt-will-use-the-rhino-based-trireme-javascri)), that's probably creating the conflict, I tried adding to sbt `dependencyOverrides ++= Set("org.mozilla" % "rhino" % "1.7.6")` and the problem persists. – ps0604 Jul 17 '18 at 22:18
  • 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. – ps0604 Jul 19 '18 at 19:12

1 Answers1

0

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.

ps0604
  • 1,227
  • 23
  • 133
  • 330