Use Local .rpt Files in Crystal Reports Java API

Assume your Java application is using Crystal Reports from the Repository Server and for whatever reason, for instance testing or debugging, you want to use a local copy of the Crystal Report .rpt file in your project, and not the one from the CR Server.

Your original code may look similar to this:

<snip>

import com.crystaldecisions.sdk.exception.SDKException;
import com.crystaldecisions.sdk.framework.CrystalEnterprise;
import com.crystaldecisions.sdk.framework.IEnterpriseSession;
import com.crystaldecisions.sdk.framework.ISessionMgr;
import com.crystaldecisions.sdk.occa.infostore.IInfoObject;
import com.crystaldecisions.sdk.occa.infostore.IInfoObjects;
import com.crystaldecisions.sdk.occa.infostore.IInfoStore;
import com.crystaldecisions.sdk.occa.managedreports.IReportAppFactory;
import com.crystaldecisions.sdk.occa.report.application.ReportClientDocument;
import com.crystaldecisions.sdk.occa.report.lib.ReportSDKException;
import com.crystaldecisions.sdk.occa.report.lib.ReportSDKExceptionBase;

<snip>

// Open report from the repository server.
ISessionMgr sessionMgr = CrystalEnterprise.getSessionMgr();
IEnterpriseSession enterpriseSession = sessionMgr.logon(
    "username", "password", "reports.someserver.com:6400", "secEnterprise");
IInfoStore iStore = (IInfoStore) enterpriseSession.getService("InfoStore");
IInfoObjects infoObjects = iStore.query(
    "Select SI_ID From CI_INFOOBJECTS Where SI_NAME like '"
    + reportName + "' And SI_INSTANCE=0");
IInfoObject infoObject = (IInfoObject) infoObjects.get(0);
IReportAppFactory reportAppFactory = (IReportAppFactory)
    enterpriseSession.getService("RASReportFactory");
ReportClientDocument clientDoc = reportAppFactory.openDocument(
    infoObject, 0, java.util.Locale.US);

<snip>

And you change it to the following:

<snip>

import com.crystaldecisions.sdk.exception.SDKException;
import com.crystaldecisions.sdk.occa.report.application.ReportClientDocument;
import com.crystaldecisions.sdk.occa.report.lib.ReportSDKException;
import com.crystaldecisions.sdk.occa.report.lib.ReportSDKExceptionBase;

<snip>

// Open report from local file.
ReportClientDocument clientDoc = new ReportClientDocument();
clientDoc.open("/home/john/eclipse_workspace/myapp/crystalreports/"
    + reportName + ".rpt", 0);

<snip>

Everything probably compiles fine, but when you run this code, you will see a run-time error saying that it’s unable to connect to the server. The reason is that your set of Crystal Report libraries files (jar files) are meant to be used in conjunction with a Crystal Report Server. If you want to use .rpt files from your local file system instead, you need a different set of Crystal Report jar files. These libraries cannot be used in conjunction with each other. You must use only one or the other. Both sets of jars provide the same API (mostly) however, internally they are quite different.

These files can be downloaded from the SAP website. Your starting point would be at following hyperlink: http://www.sdn.sap.com/irj/boc/crystalreports-java. Or you can also navigate to this page starting at http://www.sdn.sap.com/, then follow these links: “Business Analytics” -> “Business Intelligence” -> “Crystal Reports for Eclipse”.

From there, click the “Download Now” link under the Crystal Reports for Eclipse Resources.

On the new page you should find a link to download the “Runtime Libraries”. They are described as “Add the SAP Crystal Reports runtime engine to any Java application.”. Below is a list of the jar files that may be included in the CR Runtime Libraries, just to give you a general idea. The actual list of files may differ depending on the CR Runtime version.

CrystalCommon2.jar
CrystalReportsRuntime.jar
JDBInterface.jar
com.azalea.ufl.barcode.1.0.jar
commons-collections-3.1.jar
commons-configuration-1.2.jar
commons-lang-2.1.jar
commons-logging.jar
cvom.jar
icu4j.jar
jai_imageio.jar
jrcerom.jar
keycodeDecoder.jar
log4j.jar
logging.jar
pfjgraphics.jar
webreporting-jsf.jar
webreporting.jar
xpp3.jar
DatabaseConnectors.jar
QueryBuilder.jar
XMLConnector.jar

To compare with the files from the Server version:

asn1.jar
cecore.jar
celib.jar
ceplugins.jar
cereports.jar
certj.jar
cesession.jar
cewca.jar
corbaidl.jar
ebus405.jar
freessl201.jar
jsafe.jar
log4j.jar
MetafileRenderer.jar
rasapp.jar
rascore.jar
reportsourcebridge.jar
serialization.jar
sslj.jar
URIUtil.jar
webreporting.jar

Again, the actual files may differ depending on the version of CR libraries in your project.

Note that if you switch between these libraries in your project, it is recommended to recompile your code. This is because the resulting class files (binaries) of your application may actually be different based on which set of CR libraries is included in the CLASSPATH (build path). For instance if you compile your code using the CR libraries to use local .rpt files and then execute the application with the CR server libraries, you may run into a NoClassDefFoundError such as the one shown below:

java.lang.NoClassDefFoundError: com.crystaldecisions.sdk.occa.report.exportoptions.IExportFormatOptions

Leave a Reply

Your email address will not be published. Required fields are marked *

*