Search code examples
jakarta-eecrystal-reports

How to implement Crystal Reports in Java EE


I have a Java EE web application. I would like to use reporting in my application, but I don't know to how to use Crystal Reports in Java EE.

I just want to know whether the Crystal Reports Software is required when creating reports in a Java EE web application?


Solution

  • Crystal Reports is very crude in a Java EE application. I'm not sure they even actively support their Java libraries anymore. In any case, here is how we got CR to work (but we are now moving away, replacing with PDFBox with PDF fields).

    In your web.xml, put something like the following:

    <context-param>
        <param-name>crystal_image_uri</param-name>
        <param-value>/crystalreportviewers</param-value>
    </context-param>
    <context-param>
        <param-name>crystal_image_use_relative</param-name>
        <param-value>webapp</param-value>
    </context-param>
    <servlet>
        <servlet-name>CrystalReportViewerServlet</servlet-name>
        <servlet-class>com.crystaldecisions.report.web.viewer.CrystalReportViewerServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>CrystalReportViewerServlet</servlet-name>
        <url-pattern>/CrystalReportViewerHandler</url-pattern>
        <url-pattern>/faces/CrystalReportViewerHandler</url-pattern>
    </servlet-mapping>
    <resource-ref>
        <description>database reference factory for crystal report</description>
        <res-ref-name>jdbc/MyCrRef</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
        <res-sharing-scope>Shareable</res-sharing-scope>
    </resource-ref>
    

    Put the crystalreportsviewers and Java_CRJ12_Web_View folders in your web root. Add the crystal-tags-reportviewer.tld in the WEB-INF directory. Put all of your reports in WEB-INF/classes.

    You can reuse their CRHelper.java class with much changes.

    Add the following CRConfig.xml in the the WEB-INF directory:

    <?xml version="1.0" encoding="utf-8"?>
    
    <CrystalReportEngine-configuration>
        <reportlocation>../..</reportlocation>
        <timeout>0</timeout>
        <ExternalFunctionLibraryClassNames>
            <classname></classname>
        </ExternalFunctionLibraryClassNames>
    </CrystalReportEngine-configuration>
    

    Include jars in your project/build:

    com.azalea.ufl.barcode.1.0.jar
    CrystalCommon2.jar
    CrystalReportsRuntime.jar
    cvom.jar
    DatabaseConnectors.jar
    derby.jar (if using debry)
    icu4j.jar
    jai_imageio.jar
    JDBInterface.jar
    jrcerom.jar
    keycodeDecoder.jar
    log4j.jar
    logging.jar
    msbase.jar
    mssqlserver.jar
    msutil.jar
    pfjgraphics.jar
    QueryBuilder.jar
    webreporting-jsf.jar
    webreporting.jar
    xpp3.jar
    Xtreme.jar
    

    That's the basic setup. Now, you'll have to write your report code, and they do have example of that. I just don't have links readily available.