0

I have a Jasper template that consumes JSON data. I have a JsonQL as language for the datasource. The template compiles fine locally and generates a PDF preview.

But when we try to execute this on the server (standalone app using jasperreports 6.4.0 as a dependency), I get this error message:

org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.NoClassDefFoundError: antlr/TokenStream at org.springframework.web.servlet.DispatcherServlet.triggerAfterCompletionWithError(DispatcherServlet.java:1302) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:977) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:968)

I have checked the pom file for net.sf.jasperreports 6.4.0 and it has this as a dependency:

    <dependency>
        <groupId>antlr</groupId>
        <artifactId>antlr</artifactId>
        <version>2.7.5</version>
        <optional>true</optional>
    </dependency>

So I can't figure out why I get a NoClassDefFoundError for antrl.TokenStream. I found some posts online that say use Antlr 2.7.7 but this is the Jasper engine pom so I can't overwrite it easily. Could there be any other reason?

We have lots of other templates that work just fine. This is the first one that uses JsonQL. Is that a factor?

  • Have you tried doing a project clean in your IDE, checked if the project build path is correct and also executed a mvn clean install, just to make sure that all the dependencies are available in your local repository before you proceed...? – robot_alien May 23 '18 at 10:26
  • Because the dependency is optional in jasperreports's pom.xml a maven build will not fetch it. You need to manually add it in your project's pom.xml. – Narcis May 23 '18 at 11:24
  • Thanks @robot_alien for your response. I can see antlr 2.7.5 in my local repository. And opening the jar shows it has the TokenStream class within. Really puzzled. To add to that, I can see a TokenStream interface defined here - http://www.antlr.org/api/Java/org/antlr/v4/runtime/TokenStream.html – Vishal Sawant May 23 '18 at 12:28
  • Thanks @Narcis, I will try that as well. – Vishal Sawant May 23 '18 at 12:30
  • 1
    For what it is worth, the suggestion by @Narcis worked. Adding a dependency to the application pom worked. Still puzzled why the JVM couldn't find the class def, but the linked question has a good explanation of the difference between ClassNotFound and ClassDefNotFoundError - https://stackoverflow.com/a/5756989/9401183 – Vishal Sawant May 24 '18 at 11:30

0 Answers0