Announcement Announcement Module
Collapse
No announcement yet.
Spring-driven Jasper compilation fails? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring-driven Jasper compilation fails?

    I'm running Spring MVC with Jasper reports in tomcat 5.0.28. Spring initiates the compilation of my jasper reports .jrxml file. I get a stack dump (below) saying that compilation failed, and the top couple frames are from jasper code. In addition to the stack dump, there is a large amount of error output that appears to be from a Java compiler (also below). All of these errors complain of being unable to find jasper reports classes, classes which are right there in the jar with the Jasper compiler. I've tried placing the jasper jar in tomcat's common/lib directory, which did not help.

    the evidence....

    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean wit
    h name 'merchant_status_report' defined in null: Initialization of bean failed;
    nested exception is org.springframework.context.ApplicationContextExce ption: Cou
    ld not parse JasperReports report for URL [/WEB-INF/jasper-reports/merchant_stat
    us.jrxml]; nested exception is net.sf.jasperreports.engine.JRException: Errors w
    ere encountered when compiling report expressions class file:
    See error messages above.
    org.springframework.context.ApplicationContextExce ption: Could not parse JasperR
    eports report for URL [/WEB-INF/jasper-reports/merchant_status.jrxml]; nested ex
    ception is net.sf.jasperreports.engine.JRException: Errors were encountered when
    compiling report expressions class file:
    See error messages above.
    net.sf.jasperreports.engine.JRException: Errors were encountered when compiling
    report expressions class file:
    See error messages above. at net.sf.jasperreports.engine.design.JRAbstractClass Compiler.compileRep
    ort(JRAbstractClassCompiler.java:120)
    at net.sf.jasperreports.engine.design.JRDefaultCompil er.compileReport(JR
    DefaultCompiler.java:105)
    at org.springframework.web.servlet.view.jasperreports .AbstractJasperRepo
    rtsView.loadReport(AbstractJasperReportsView.java: 454)
    at org.springframework.web.servlet.view.jasperreports .AbstractJasperRepo
    rtsView.initApplicationContext(AbstractJasperRepor tsView.java:320)
    at org.springframework.context.support.ApplicationObj ectSupport.setAppli
    cationContext(ApplicationObjectSupport.java:79)
    at org.springframework.context.support.ApplicationCon textAwareProcessor.
    postProcessBeforeInitialization(ApplicationContext AwareProcessor.java:84)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBean
    Factory.applyBeanPostProcessorsBeforeInitializatio n(AbstractAutowireCapableBeanF
    actory.java:248)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBean
    Factory.createBean(AbstractAutowireCapableBeanFact ory.java:362)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean
    (AbstractBeanFactory.java:226)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean
    (AbstractBeanFactory.java:147)
    at org.springframework.beans.factory.support.DefaultL istableBeanFactory.
    preInstantiateSingletons(DefaultListableBeanFactor y.java:275)
    at org.springframework.context.support.AbstractApplic ationContext.refres
    h(AbstractApplicationContext.java:318)
    at org.springframework.web.servlet.view.ResourceBundl eViewResolver.initF
    actory(ResourceBundleViewResolver.java:183)
    at org.springframework.web.servlet.view.ResourceBundl eViewResolver.loadV
    iew(ResourceBundleViewResolver.java:131)
    at org.springframework.web.servlet.view.AbstractCachi ngViewResolver.crea
    teView(AbstractCachingViewResolver.java:141)
    at org.springframework.web.servlet.view.AbstractCachi ngViewResolver.reso
    lveViewName(AbstractCachingViewResolver.java:79)
    at org.springframework.web.servlet.DispatcherServlet. resolveViewName(Dis
    patcherServlet.java:950)
    at org.springframework.web.servlet.DispatcherServlet. render(DispatcherSe
    rvlet.java:909)
    at org.springframework.web.servlet.DispatcherServlet. doDispatch(Dispatch
    erServlet.java:705)
    at org.springframework.web.servlet.DispatcherServlet. doService(Dispatche
    rServlet.java:625)
    at org.springframework.web.servlet.FrameworkServlet.s erviceWrapper(Frame
    workServlet.java:386)
    at org.springframework.web.servlet.FrameworkServlet.d oGet(FrameworkServl
    et.java:346)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:689)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:802)
    at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(Appl
    icationFilterChain.java:237)
    ..... more catalina stuff......

    2005-09-13 09:00:45 /home/shea/work/dev/itransact.jfe/run/tomcat-5.0.28/app_stat
    us_report.java:4: package net.sf.jasperreports.engine does not exist
    import net.sf.jasperreports.engine.*;
    ^
    /home/shea/work/dev/itransact.jfe/run/tomcat-5.0.28/app_status_report.java:5: pa
    ckage net.sf.jasperreports.engine.fill does not exist
    import net.sf.jasperreports.engine.fill.*;
    ^
    /home/shea/work/dev/itransact.jfe/run/tomcat-5.0.28/app_status_report.java:14: p
    ackage net.sf.jasperreports.engine does not exist
    import net.sf.jasperreports.engine.*;
    ^
    /home/shea/work/dev/itransact.jfe/run/tomcat-5.0.28/app_status_report.java:15: p
    ackage net.sf.jasperreports.engine.data does not exist
    import net.sf.jasperreports.engine.data.*;
    ^

    etc...

  • #2
    Hi Gary,

    I came across a similar problem yesterday. Analysis showed that the compilation process really doesn't have anything to do with the servlet container. Instead, the code spawns a new compilation process using the system classpath.

    So the easy fix would be to add the jasper reports jar to your system classpath. A (better) idea is suggested by this developerworks article: http://www-128.ibm.com/developerwork..._olivieri.html. Before the compilation add some code somewhat similar to the following:

    Code:
    // Set the class path
    ServletContext context = getServletContext();
    System.setProperty(
            "jasper.reports.compile.class.path",
            context.getRealPath("/WEB-INF/lib/jasperreports.jar") + System.getProperty("path.separator") + context.getRealPath("/WEB-INF/classes/"));
    The only thing is that the code that loads and compiles the report is invoked in AbstractJasperReportsView.initApplicationContext() . I'm not using Spring MVC, so this isn't a problem for me, but you'll need to find a hook or some other way to set that property before this is invoked.

    Hope this is of some assistance.

    Regards,
    Geoff

    Comment


    • #3
      Originally posted by luxaeterna
      Hi Gary,

      I came across a similar problem yesterday. Analysis showed that the compilation process really doesn't have anything to do with the servlet container. Instead, the code spawns a new compilation process using the system classpath.
      Geoff -- Thanks, that makes sense. I was wondering if the compilation was happening in a separate JVM, but I had no idea how to communicate the classpath requirement to it. Now I do!

      Gary

      Comment


      • #4
        Spring Driven Jasper Reports gives Error in Browser

        Hi To all,
        I am using Spring Framework and Japser Reports. I am able to succesfully compile the JasperDemo project which is present on CVS of Spring.

        I made the War and deployed it in Tomcat5.5 when i run it tin browser, it gives the following error:



        exception

        javax.servlet.ServletException: Servlet.init() for servlet jrtest threw exception
        org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:105)
        org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:148)
        org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:856)
        org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.processConnection(Http11Protocol.jav a:744)
        org.apache.tomcat.util.net.PoolTcpEndpoint.process Socket(PoolTcpEndpoint.java:527)
        org.apache.tomcat.util.net.LeaderFollowerWorkerThr ead.runIt(LeaderFollowerWorkerThread.java:80)
        org.apache.tomcat.util.threads.ThreadPool$ControlR unnable.run(ThreadPool.java:684)
        java.lang.Thread.run(Unknown Source)


        root cause

        org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'subReport' defined in ServletContext resource [/WEB-INF/jrtest-servlet.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.FatalBeanException: Could not instantiate class [org.springframework.web.servlet.view.jasperreports .JasperReportsPdfView]; constructor threw exception; nested exception is java.lang.IllegalAccessError: tried to access method net.sf.jasperreports.engine.design.JRDefaultCompil er.<init>()V from class org.springframework.web.servlet.view.jasperreports .AbstractJasperReportsView
        org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:355)
        org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:226)
        org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:147)
        org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:275)
        org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:317)
        org.springframework.web.context.support.AbstractRe freshableWebApplicationContext.refresh(AbstractRef reshableWebApplicationContext.java:134)
        org.springframework.web.servlet.FrameworkServlet.c reateWebApplicationContext(FrameworkServlet.java:3 05)
        org.springframework.web.servlet.FrameworkServlet.i nitWebApplicationContext(FrameworkServlet.java:250 )
        org.springframework.web.servlet.FrameworkServlet.i nitServletBean(FrameworkServlet.java:219)
        org.springframework.web.servlet.HttpServletBean.in it(HttpServletBean.java:111)
        javax.servlet.GenericServlet.init(GenericServlet.j ava:211)
        org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:105)
        org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:148)
        org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:856)
        org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.processConnection(Http11Protocol.jav a:744)
        org.apache.tomcat.util.net.PoolTcpEndpoint.process Socket(PoolTcpEndpoint.java:527)
        org.apache.tomcat.util.net.LeaderFollowerWorkerThr ead.runIt(LeaderFollowerWorkerThread.java:80)
        org.apache.tomcat.util.threads.ThreadPool$ControlR unnable.run(ThreadPool.java:684)
        java.lang.Thread.run(Unknown Source)






        I am attaching my jrtest-servlet.xml



        <?xml version="1.0" encoding="UTF-8"?>
        <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

        <beans>

        <!-- ResourceBundleViewResolver is the ideal way in which to configure a whole set of JasperReports
        views that require nothing more than the URL for configuration. -->
        <bean id="viewResolver" class="org.springframework.web.servlet.view.Resour ceBundleViewResolver">
        <property name="basename">
        <value>views</value>
        </property>
        </bean>

        <!-- If a JasperReports view requires more complex configuration then use the BeanNameViewResolver to
        map a given view name to a given view bean -->

        <bean id="nameViewResolver" class="org.springframework.web.servlet.view.BeanNa meViewResolver"/>

        <!-- Here you can see that we have configured the JasperReportsPdfView class with a Map containing the
        path to the sub-report file. The key used in the Map corresponds to the key used for the
        sub-report inside the master report file. -->

        <bean id="subReport" class="org.springframework.web.servlet.view.jasper reports.JasperReportsPdfView">
        <property name="url">
        <value>/WEB-INF/reports/subReportParent.jasper</value>
        </property>

        <property name="subReportUrls">
        <map>
        <entry key="ProductsSubReport">
        <value>/WEB-INF/reports/subReportChild.jasper</value>
        </entry>
        </map>
        </property>

        <property name="subReportDataKeys">
        <value>SubReportData</value>
        </property>

        <property name="reportDataKey">
        <value>dataSource</value>
        </property>
        </bean>

        <bean id="htmlReport" class="org.springframework.web.servlet.view.jasper reports.JasperReportsHtmlView">
        <property name="url">
        <value>/WEB-INF/reports/simpleReport.jasper</value>
        </property>
        <property name="exporterParameters">
        <map>
        <entry key="net.sf.jasperreports.engine.export.JRHtmlExpo rterParameter.HTML_FOOTER">
        <value>Footer by Spring!&lt;/td&gt;&lt;td width="50%"&gt;&amp;nbsp; &lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/body&gt;&lt;/html&gt;</value>
        </entry>
        </map>
        </property>
        </bean>

        <bean id="urlMapping" class="org.springframework.web.servlet.handler.Sim pleUrlHandlerMapping">
        <property name="mappings">
        <props>
        <prop key="/*.*">controller</prop>
        </props>
        </property>
        </bean>

        <bean id="controller" class="org.springframework.samples.jasperdemo.web. ReportController">

        <property name="methodNameResolver">
        <ref local="resolver"/>
        </property>
        </bean>

        <bean id="resolver" class="org.springframework.web.servlet.mvc.multiac tion.PropertiesMethodNameResolver">
        <property name="mappings">
        <props>
        <prop key="/simpleReport.pdf">handleSimpleReport</prop>
        <prop key="/simpleReportPost.pdf">handleSimpleReportPost</prop>
        <prop key="/simpleReportPost.action">handleSimpleReportPost</prop>
        <prop key="/simpleReportCompile.pdf">handleSimpleReportCompile </prop>
        <prop key="/simpleReportHtml.html">handleSimpleReportHtml</prop>
        <prop key="/simpleReportCsv.csv">handleSimpleReportCsv</prop>
        <prop key="/simpleReportExcel.xls">handleSimpleReportExcel</prop>
        <prop key="/simpleReportMulti.*">handleSimpleReportMulti</prop>
        <prop key="/subReport.pdf">handleSubReport</prop>
        <prop key="/exporterParameters.html">handleExporterParameters</prop>
        </props>
        </property>
        </bean>
        </beans>

        Comment

        Working...
        X