Hi,
Follow these steps to access crystal reports using Java.
1. Create a WEB-INF\lib folder in the root of your Java *.class file
folder tree. For example:
com\
foobar\
WEB-INF\
lib\
2. Copy the following JAR files from �\Program Files\Common
Files\Business Objects\3.0\java\lib, ...\Program Files\Common
Files\Business Objects\3.0\java\lib\external, and ...\Program
Files\Common Files\Business
Objects\3.0\crystalreportviewers115\JavaViewer folders to the
WEB-INF\lib folder:
�
ReportViewer.jar
�
jrcerom.jar
�
Concurrent.jar
�
CrystalCharting.jar
�
CrystalCommon.jar
�
CrystalContentModels.jar
�
CrystalExporters.jar
�
CrystalExportingBase.jar
�
CrystalFormulas.jar
�
CrystalQueryEngine.jar
�
CrystalReportEngine.jar
�
CrystalReportingCommon.jar
�
icu4j.jar
�
keycodeDecoder.jar
�
log4j.jar
�
MetafileRenderer.jar
�
rasapp.jar
�
rascore.jar
�
rpoifs.jar
�
Serialization.jar
�
URIUtil.jar
�
xercesImpl.jar
�
xml-apis.jar
3. Add the above JAR files to your classpath and ensure that
ReportViewer.jar and jrcerom.jar are the first two JARs listed.
NOTE
If you are using Eclipse, you may have to quit Eclipse, edit your classpath file to move the
JARs to the beginning of the list, and then start Eclipse. Otherwise, you will receive a
"java.lang.IncompatibleClassChangeError: Implementing class" exception at run time.
4. Copy the CRConfig.xml file from your ...\Program Files\Common
Files\Business Objects\3.0\java folder to the root of your Java *.class
folder tree. For example:
CRConfig.xml
com\
foobar\
WEB-INF\
lib\
5. Edit the CRConfig.xml file's <reportlocation> tag to specify the
relative path to the folder containing the .rpt files. The path is
relative to the WEB-INF\lib folder. For example, if you specify ".",
then the .rpt file is loaded from the WEB-INF\lib folder.
<?xml version="1.0" encoding="utf-8"?>
<CrystalReportEngine-configuration>
<reportlocation>.</reportlocation>
6. Add code similar to the following to create the ReportViewerBean,
open the report, set the report on the viewer, and start the viewer:
import java.awt.*;
import javax.swing.*;
import com.crystaldecisions.ReportViewer.*;
// Use this for talking to JRC in-process
import com.crystaldecisions.reports.sdk.*;
import
com.crystaldecisions.sdk.occa.report.reportsource.*;
public class HelloWorldSwing
{
private static void createAndShowGUI()
{
try
{
//Make sure we have nice window decorations.
JFrame.setDefaultLookAndFeelDecorated(false);
//Create and set up the window.
NOTE
If you are using Eclipse, you may have to quit Eclipse, edit your classpath file to move the
JARs to the beginning of the list, and then start Eclipse. Otherwise, you will receive a
"java.lang.IncompatibleClassChangeError: Implementing class" exception at run time.
4. Copy the CRConfig.xml file from your ...\Program Files\Common
Files\Business Objects\3.0\java folder to the root of your Java *.class
folder tree. For example:
CRConfig.xml
com\
foobar\
WEB-INF\
lib\
5. Edit the CRConfig.xml file's <reportlocation> tag to specify the
relative path to the folder containing the .rpt files. The path is
relative to the WEB-INF\lib folder. For example, if you specify ".",
then the .rpt file is loaded from the WEB-INF\lib folder.
<?xml version="1.0" encoding="utf-8"?>
<CrystalReportEngine-configuration>
<reportlocation>.</reportlocation>
6. Add code similar to the following to create the ReportViewerBean,
open the report, set the report on the viewer, and start the viewer:
import java.awt.*;
import javax.swing.*;
import com.crystaldecisions.ReportViewer.*;
// Use this for talking to JRC in-process
import com.crystaldecisions.reports.sdk.*;
import
com.crystaldecisions.sdk.occa.report.reportsource.*;
public class HelloWorldSwing
{
private static void createAndShowGUI()
{
try
{
//Make sure we have nice window decorations.
JFrame.setDefaultLookAndFeelDecorated(false);
//Create and set up the window.
JFrame frame = new JFrame("HelloWorldSwing");
frame.setTitle("Testing 1, 2, 3");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ReportViewerBean viewer = new ReportViewerBean();
viewer.init(new
String[0], null, null, null);
ReportClientDocument rpt =
new ReportClientDocument();
rpt.open("MyReport.rpt", 0);
IReportSource rptSource = rpt.getReportSource();
viewer.setReportSource(rptSource);
frame.getContentPane().add
(viewer, BorderLayout.CENTER);
frame.setSize(700, 500);
frame.setVisible(true);
viewer.start();
}
catch (Exception exception)
{
System.out.println(exception.toString());
}
}
public static void main(String[] args)
{
javax.swing.SwingUtilities.invokeLater(new
Runnable()
{
public void run()
{
createAndShowGUI();
}
});
}
}
i've followed all the steps given in spec, but i'm getting the following exception
com.crystaldecisions.sdk.occa.report.lib.ReportSDKException: Unexpected error determining relative path---- Error code:-2147467259 Error code name:failed
at com.crystaldecisions.reports.reportengineinterface.a.a.b.a(Unknown Source)
at com.crystaldecisions.reports.sdk.ReportClientDocument.open(Unknown Source)
at pTravelImpressions.Channels.createAndShowGUI(Channels.java:51)
at pTravelImpressions.Channels$1.run(Channels.java:83)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:168)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:442)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:234)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:141)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:132)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:124)
Can anyone help me regarding.
ThanX