The Kat's Work - Blog
Main | Blog | Registration | Login
Thursday
2024-04-25
10:23 PM
Welcome Guest | RSS
Main » 2010 » December » 17

Crystal is good, however generally to run any reports you need at least the report viewer installed on someone’s pc. That sucks! So here is how to make a distributable jar file that when clicked will run a crystal report without the need for other installed software.

First off you need to install the Crystal Reports for Eclipse plugin into Eclipse. Instructions and download can be found here http://www.sdn.sap.com/irj/sdn/crystalreports-java however SAP has an annoying habit of moving their pages about 7 times a month.

Okay Dokey, so you now have crystal reports abilities in eclipse. The nice chaps at SAP provide this plug in free of charge and only ask that it not be resold. So fell free to use it but don’t make it part of something you intend to sell commercially, or you’ll have to buy a licence.

You can now add Crystal reports to existing webapps (which I’ll tutorial later), and also more importantly for this tutorial make standalone "jarrable” crystal reports applications.

In Eclipse go to file -> New -> other. Select folder "Crystal Reports” than Crystal Reports Java Project. Call it something meaningful. Press finish.

You now have a working java application that can run Crystal reports, well done.

At this point we can just jar this up and run it. Right Click the project click Export….
Go to Java folder choose runable jar file. Click Next. The sample project already has launch configurations set up so in the box choose SampleViewerFrameClient, than choose where you want the jar to go.

You now have a run anywhere crystal report viewer. This jar when run will ask you which report you wish to run. Find the report you want and run hoorah!……That’s not what we want though, we want a user to click this report and a particular report to be run. Further we want the report to be bundled into the library (jar) for distribution.

So now we want to set up the application to just choose the report we want and also to include this file in the jar. To include the report in the jar you must add it to the src folder. Eclipse when making a runnable jar is quite selective on what it exports. You can make it export more than the src folder but you’ll have difficulties referencing the report if it is anywhere other than the src folder.

So with added the report to src folder. Now open the report in eclipse. The connection for the report must be jdbc. If it is not you must change it, remembering to include any needed external libraries (i.e jtds) into the project build path.

Now the coding. The sampleViewerFrame class has almost everything we need. So lets copy it. Rename the copy something meaningful. First off you’ll need to add a new private function as below.

  private void loadPreSetReport()throws ReportSDKException{
   
      
       
        reportClientDocument = new ReportClientDocument ();
        reportClientDocument.setReportAppServer(ReportClientDocument.inprocConnectionString);
        reportClientDocument.open ("<YourReport.rpt>", OpenReportOptions._openAsReadOnly);
       
       
    }

This function will replace the LoadReport function. So next we need to replace the reference to loadReport() with loadPreSetReport() in function showReport.

Next we need to copy the SampleViewerFrameClient class. This will prevent us having to recreate the launch Configuration. Name it something meaningful. Replace its static reference to SampleViwerFrame with your version.

Optional part, you can preset login values in the Frame class. Simply open your version of SampleViewerFrame go to function setDatabaseLogon and uncomment line

CRJavaHelper.logonDataSource (reportClientDocument, "username", "password");

Replace username and password as necessary. Be warned though this will make your report run able by anyone who acquires your jar file.

Right Click the project click Export….
Goto Java folder choose runable jar file. Click Next. Choose your custom version of SampleViewerFrameClient, than choose where you want the jar to go.

Congratulations you now have a single file containing a "portable” version of the report.

Views: 63216 | Added by: The_Kat | Date: 2010-12-17 | Comments (10)

Login form
Adverts
Search
Calendar
«  December 2010  »
SuMoTuWeThFrSa
   1234
567891011
12131415161718
19202122232425
262728293031
Entries archive
Site friends
  • Create your own site
  • Spree4.com
  • My Blog
  • Statistics

    Total online: 1
    Guests: 1
    Users: 0
    spree4
    Copyright MyCorp © 2024
    Website builderuCoz