Está en la página 1de 28

Crystal Reports for Eclipse

Getting Started Guide

Crystal Reports for Eclipse


Getting Started Guide

Table of Contents
1 Creating a Crystal Reports Web Application ..................................................... 2
2 Designing a Report off the Xtreme Embedded Derby Database......................... 11
3 Running a Crystal Reports Web Application.................................................... 20
4 Creating a New Viewer Page ........................................................................ 22
5 Snippets ................................................................................................... 25
6 Help ......................................................................................................... 28
Crystal Reports for Eclipse
Getting Started Guide

1 Creating a Crystal Reports Web Application


Crystal Reports for Eclipse includes many tools to assist developers with the building of
applications that require a powerful and versatile presentation layer. One such tool is the
Crystal Reports Web Application wizard which will walk users through the creation of a
web application which will contain Crystal Reports. This tutorial will explain the steps a
user will follow to complete this process
1) Select “File” | “New” | “Project…”
2) Expand the “Crystal Reports” folder and select “Crystal Reports Web Project”.

3) Click “Next”.
4) Give the project a name in the “Name:” field.
5) Make sure Tomcat is configured with a path to the Java SDK. You should only
have to do this once in your workspace:

PAGE 2
Crystal Reports for Eclipse
Getting Started Guide

a. Go to “Target runtime:”, and click “New…”.


b. Expand “Apache” and select “Apache Tomcat v5.0”. Click “Next”.

PAGE 3
Crystal Reports for Eclipse
Getting Started Guide

c. Specify the “Tomcat installation directory:”, e.g. “C:\Program


Files\Business Objects\Tomcat”.
d. Click “Installed JREs…”.
e. Click “Add…”
f. For “JRE name”, specify “JDK 1.4.2”.
g. For “JRE home directory”, specify your Java SDK directory, e.g.
“C:\j2sdk1.4.2_08”.

PAGE 4
Crystal Reports for Eclipse
Getting Started Guide

h. Click OK.
i. Select “JDK 1.4.2” in the “Installed JREs” list.
j. Click OK.
k. Under the “JRE” field in the “New Server Runtime” dialog, select “JDK
1.4.2”.

PAGE 5
Crystal Reports for Eclipse
Getting Started Guide

l. Click “Finish”.
6) Click “Next >”.
7) The next page of the wizard presents the user with the option select which
“facets” they wish to add to the application. A facet defines which runtime
environments will be added to the application. By default the Crystal Reports Java
Reporting Component will be selected

PAGE 6
Crystal Reports for Eclipse
Getting Started Guide

8) Click “Next >”.


9) Users can modify the Context Root for their application on this next page of the
wizard. For this demo we will keep the default settings. Click “Next >”.

PAGE 7
Crystal Reports for Eclipse
Getting Started Guide

10) This next dialog allows users to choose whether they wish to add our sample
database and reports as well as a new blank report to their web application

PAGE 8
Crystal Reports for Eclipse
Getting Started Guide

11) Click “Finish” to create your project.


12) When asked to accept the Sun license agreement to cache
http://java.sun.com/xml/ns/j2ee/j2ee_1_4.xsd, click “I Agree”.

PAGE 9
Crystal Reports for Eclipse
Getting Started Guide

13) Click “Yes” to open the J2EE perspective.


The J2EE Perspective will contain a Project Explorer which allows the user to navigate the
different projects contained in their workspace. When the user expands the Dynamic Web
Project heading in the Project Explorer they should notice their newly created web
application. This web application will contain all of the required files for generating
reports at runtime. As well, if users opted to add the sample reports and database they
will notice a folder titled “Samples” within the Web Content folder containing the 3
sample reports. Finally, if the user opted to add a new Blank Crystal Report file to the
project they should notice 2 files within the root of the Web Content folder. One will be
titled Crystal Report1.rpt which is the report file, and the other will be titled
CrystalReport1-viewer.jsp which is a Java Server Page containing the required code to
view the new report over the web.

PAGE 10
Crystal Reports for Eclipse
Getting Started Guide

2 Designing a Report off the Xtreme Embedded Derby


Database
This release of Crystal Reports for Eclipse includes a sample database built using
Apache’s open source Derby Database. This is added to new Crystal Reports Web Projects
by default to allow users to get up and running in no time. For other data sources Crystal
Reports for Eclipse includes a Deployment Assistance feature which will assist developers
by attempting to ensure that the required database drivers are present at runtime. Follow
the steps below to create a new report off of our Xtreme Sample Database

1) After the Crystal Reports Web Project has been created, you should notice that a
file titled CrystalReports1.rpt has been added to the Web Content folder of the
newly created Web Project. Double-clicking this file will open it up in the Crystal
Reports editor. This action should also change the user’s Eclipse Perspective to be
“Crystal Reports”
2) Go to the “Database Explorer”
3) Right-click on the “Connections” node and choose “New Connection…”

PAGE 11
Crystal Reports for Eclipse
Getting Started Guide

4) This action will launch the Database Explorer wizard. Expand the Derby entry in
the Database Manager and select the 10.1 option
5) For the Database location enter classpath:/Xtreme .This will allow the engine to
look for the Derby database within a JAR file located in the CLASSPATH.
6) Set the information in the dialog to the following. For the “Class location”, select
both the derby.jar and Xtreme.jar from your
“.\eclipse\plugins\com.businessobjects.crystalreports.samples_1.0.0.vX
XX\SampleDatabases” directory:

PAGE 12
Crystal Reports for Eclipse
Getting Started Guide

7) The JDBC driver class and Connection URL should be automatically populated.
8) Click “Test Connection” to ensure that you can connect to the database
9) Click “Next”, and then click “Finish”.

PAGE 13
Crystal Reports for Eclipse
Getting Started Guide

10) From the Database Explorer, expand “Xtreme” / “Schemas” / “APP” / “Tables” to
see the available tables

11) Drag the “CUSTOMER” and “ORDERS” tables onto the report. Alternatively, you
can right-click a table and select the option “Add to New Report” or “Add to
Current Report”
12) This will add the CUSTOMER and ORDERS table to the Data pane of the Crystal
Reports editor. Create a relationship between the two tables by dragging the
CUSTOMER_ID field from the CUSTOMER table and dropping it on the
CUSTOMER_ID field on the ORDERS table

PAGE 14
Crystal Reports for Eclipse
Getting Started Guide

13) In the report designer, switch back to the “Layout” tab to begin designing the
report
14) From the Field Explorer, right-click on the COUNTRY field in the CUSTOMER table
and select the option to “Group on Field”. This will group all of the data report
based on Country

PAGE 15
Crystal Reports for Eclipse
Getting Started Guide

15) Repeat this same step to add a group based on the CUSTOMER_NAME field from
the CUSTOMER table. You will notice that Crystal Reports includes pre-existing
logic to decrease the group-level font size as you add more groups. Obviously the
report designer will be able to format these fields as they deem necessary. Your
report should now look similar to the layout below:

PAGE 16
Crystal Reports for Eclipse
Getting Started Guide

16) Now select ORDER_ID, ORDER_AMOUNT and ORDER_DATE from the ORDERS
table. Drag the multiple selection and drop in the Body section of the report. This
will add the 3 data fields to the Body section as well as 3 data labels to the Page
Header section
17) Right-click on the ORDERS.ORDER_AMOUNT field and select the “Summarize”
option

PAGE 17
Crystal Reports for Eclipse
Getting Started Guide

18) This will add a Summary field to the Group1 Footer section.
19) Add some minimal report formatting to adjust the section heights. You can do this
via the Properties view of each section by changing the Height property.
Alternatively, you can drag the height indicator of the section to reduce or
increase the size of the height.
20) Additionally add some text formatting to highlight Group Headings and Total
amounts
21) Click on the “Preview” tab to preview the report. Your report should look similar to
the following:

PAGE 18
Crystal Reports for Eclipse
Getting Started Guide

This guide is intended to be an introduction to the product. It is recommended that


the user continues to experiment with the available properties and Report Objects to
create the required level of formatting. Additional guides exploring advanced report

PAGE 19
Crystal Reports for Eclipse
Getting Started Guide

design techniques will be made available on Business Objects’ Eclipse Zone


(http://diamond.businessobjects.com/eclipse)

3 Running a Crystal Reports Web Application


Running a report in a web application is a very simple process within Crystal Reports
for Eclipse. By default, the blank report which is added to the Crystal Reports Web
Project has an accompanying JSP which will serve up the report viewer at runtime.
This file will be named CrystalReport1-viewer.jsp and should be found in the root of
the Web Content folder.
1) In the Project Explorer, right-click on “CrystalReport1-viewer.jsp”.
2) Select “Run As” | “Run on Server”.
3) Select “Apache” / “Tomcat v5.0 Server” and click “Next”.
4) Make sure “CrystalReportsForEclipse” (or whatever you named your project) is
listed under “Configured projects:”, and click “Finish”.
5) This will launch CrystalReport1-viewer.jsp in an Internet browser window
embedded in the IDE (note: if your Tomcat server was configured to use a JRE
instead of a JDK you may experience an error at this point as Tomcat will not be
able to compile the JSP):

PAGE 20
Crystal Reports for Eclipse
Getting Started Guide

PAGE 21
Crystal Reports for Eclipse
Getting Started Guide

4 Creating a New Viewer Page


Creating a new Viewer JSP page off existing reports is just as easy as using the
default viewer page which was created in Step 5. In this demo we will build a Crystal
Reports viewer JSP page to show the Sample Reports included with this release of
Crystal Reports for Eclipse
1) Expand the Web Content\Sample Reports folder in the Navigator or Project
Explorer view.

2) Right-click on “Consolidated Balance Sheet.rpt” and select the “Crystal Reports”-


>”Create Viewer JSP” option

PAGE 22
Crystal Reports for Eclipse
Getting Started Guide

3) This action will launch a wizard which will provide the Developer with a number of
options. Crystal Reports for Eclipse includes a feature which will auto-generate
stub code to assist developers with coding common tasks (e.g. authenticating
against the database, passing in parameter values, exporting, etc.). There are
additional tutorials available on the Crystal Reports for Eclipse developer zone
which go into this feature in more detail. For the sake of this demo we will select
the default option: “Insert standard Tag Lib code”

PAGE 23
Crystal Reports for Eclipse
Getting Started Guide

4) Clicking “OK” on this wizard will add a new file to the same folder as the report
called “Consolidated Balance Sheet-viewer.jsp”
5) In the Project Explorer, right-click on “Consolidated Balance Sheet-viewer.jsp”.
6) Select “Run As” | “Run on Server”.
7) Select “Apache” / “Tomcat v5.0 Server” and click “Next”.
8) Make sure “CrystalReportsForEclipse” (or whatever you named your project) is
listed under “Configured projects:”, and click “Finish”.
9) This will launch “Consolidated Balance Sheet-viewer.jsp” in an Internet browser
window embedded in the IDE.

PAGE 24
Crystal Reports for Eclipse
Getting Started Guide

5 Snippets
Often developers will want to have more control over the final outcome of their
presentation layer. As mentioned in the previous section Crystal Reports for Eclipse
provides developers with the “Viewer JSP Wizard” to auto-generate custom code to assist
them with the development of applications using our Java APIs. Additionally, this release
also provides a number of code snippets which will allow users to drag-and-drop code
into their JSP page. These snippets provide the developer with more control over where
the code snippet will be generated. The following snippets are provided in this release of
Crystal Reports for Eclipse:
1. Crystal Reports Viewer Tag – this will insert the required Crystal Reports
Viewer Tag Library code. The only parameter required by this snippet is the name
of the report file the viewer should be bound to
2. Open and View Report – This will open the report using the Java Reporting
Component API and view it using the Viewer API.
3. Open Report – This will open the report and create a ReportSource object. This
snippet should be used in conjunction with one of the Viewer or Export snippets
4. View Report – This snippet will add the required Viewer API calls to a page. It
will require a ReportSource object which can be returned from the “Open Report”
snippet
5. View Report and Set Database Logon - This snippet will add the required
Viewer API calls as well as the required calls to authenticate against the database
add runtime. It will require a ReportSource object which can be returned from the
“Open Report” snippet
6. Export Report to PDF - This snippet will add the required exporting calls to a
page. It will require a ReportSource object which can be returned from the “Open
Report” snippet
7. Export Report to RPT - This snippet will add the required exporting calls to a
page. It will require a ReportSource object which can be returned from the “Open
Report” snippet

To access the snippets follow these steps


1) Switch to the J2EE perspective. If it is not open then select it under Window-
>Open Perspective->Other
2) A Snippets view will be added to the bottom-center portion of the IDE
3) Expand the Crystal Reports heading

PAGE 25
Crystal Reports for Eclipse
Getting Started Guide

4) Create a new JSP page (e.g. test.jsp) by right-clicking on the Web Content folder
of the Crystal Reports Web Project and selecting New->JSP

PAGE 26
Crystal Reports for Eclipse
Getting Started Guide

5) Drag-and-drop the “Open and View Report” snippet from the Snippets view to the
JSP page (between the <BODY> tags)
6) Enter “/CrystalReport1.rpt” as the Value for the reportName variable.

PAGE 27
Crystal Reports for Eclipse
Getting Started Guide

7) Click “Insert”. This will insert the code snippet into the source of the JSP page.
8) Test the new JSP by right-clicking on it and selecting the “Run On Server” option.

6 Help
Crystal Reports for Eclipse contains the following Help Guides installed in the Eclipse Help
System:
1. Crystal Reports for Eclipse Designer Guide – this help guide provides
additional information and assistance with using the Crystal Reports editor, such
as built-in formula functions, adding database connections and modifying report
object property values
2. Crystal Reports for Eclipse Developer Guide – this help guide provides
additional developer resources, such as code snippets, walk-throughs and
JavaDocs.

PAGE 28

También podría gustarte