Using import/export scripts allows you to export and import content from the JasperServer repository. This tutorial utilizes import and export scripts to mass upload reports from a development environment to a production environment.
Additionally, it showcases how to take advantage of the JasperServer plugin for iReport. This tutorial can be used in any development and production environment; especially in situations where both development and production environments are using different technologies.
First, we need to configure the js-import and js-export scripts to connect to the JasperServer repository. The scripts are located in the <jasperserver-install>/scripts directory.
Check your jasperserver configuration in this file : <jasperserver-install>\apache-tomcat\webapps\jasperserver-pro\META-INF\context.xml
Search for the following lines, which contain information about the repository database:
Obtain the following information:
With the information you obtained above, configure the import/export scripts by editing the file :
The first line configures the hibernate dialect used by the scripts.
If you are not using MySQL refer to the section 12.2 page 80 on the JasperServer-Pro-Install-Guide.pdf located in the <jasperserver-install>\docs folder.
Configure the driver, url, username, and password according to the values you obtained in Step 1.
Best Practice: To avoid confusion, a best practice is to use the js-export script on your development server and the js-import script on your production server.
Assumption: The demo samples that are provided with the installer are deployed on the development server. The production server is installed without the samples.
Best Practice: Maintain the same folder tree structure between production and other environments (for instance development or test).
By maintaining the same folder structure, you will avoid having to perform one-offs to upload reports.
Example: Export all reports within the organization_1/reports/samples folder
In a terminal (or under cmd on windows) go to your <jasperserver-install>\scripts directory
Type the following command :
js-export –uris /organizations/organization_1/reports/samples –output-zip organization_1_reports_samples.zip
--uris = indicates witch folder to extract
--output-zip = create a zip file with the specified name containing the export.
Result: The reports within the specified folder are exported along with any dependencies (such as graphics, connections) into a zip file.
Reports and dependencies are now safely stored in a zip file. Next, re-import them. The easiest import scenario is categorized by having the same folder structure in development and production environments. First, create the organization in the production environment then upload your reports.
Note: If you wish to test import/export in a single JasperServer instance reinitialize the repository prior to this step. The initialization scripts are located in the <jasperserver-install>\scripts folder.
Example: For MySQL, run the <jasperserver-install>\scripts\MySQL\jasper_init.bat (Download here), and then continue with the steps listed below.
Create the organization in the production environment.
|1||Login as superuser in your production server.|
|2||Go to Manage > Organizations|
|3||Select the root folder then click the Create Organization button|
Fill the form according to the organization settings you had from development (the organization_id must be the same)
In our sample:
Organization name = Organization
Organization_id = organization_1
Note: organization_1 is an organization that is created by default.
Once we have our organization correctly configured, then we can upload the reports using the js-import tool.
Example: In our example, make sure you have copied organization_1_reports_samples.zip into the <jasperserver-install>\scripts directory
|1||In a terminal (or under cmd on windows) go to your <jasperserver-install>\scripts directory|
Type the following command :
js-import --input-zip organization_1_reports_samples.zip
Result: The reports and dependencies are uploaded in the organization
Assumption: You already have an organization within your production environment, which differs from the development (in our example you do not have an organization using organization_1 as id).
In our example, the organization id we wish to upload our reports to is demo. This is not a best practice but a common case where development and production do not share same organization structure.
Js-Import and Js-Export scripts don’t provide a mechanism for specifying the organization id. Essentially, this limitation requires that you perform the transformation manually.
Below are the steps for defining the transformation.
Best Practice: Use a text editor such as Notepad++ to find and replace characters strings from multiple files at the same time.
Notepad ++ is a free text editor that can be downloaded here.
|1||Unzip the exported file organization_1_reports_samples.zip ,and open the contents (we later refer to it simply as the export folder)|
|2||Open Notepad++ or your favorite text editor|
Search and drag and drop all .xml files (reports) from your export folder into Notepad++
Go to Search > Replace, and then specify the following:
· Find what: /organizations/organization_1 (the original organization id)
· Replace with: /organizations/demo (the target organization id)
Then click Replace in all opened documents
Result : The export folder is now specified as Demo, rather than organization_1
Create a zip file containing the export folder with the newly modified files.
Important: The root of your zip file should contain the folder resources and the file index.xml
Name the zip file demo_reports_samples.zip
|6||In a terminal (or under cmd on windows) go to your <jasperserver-install>\scripts directory|
Type the following command :
js-import --input-zip demo_1_reports_samples.zip
Result: The reports are now uploaded in the demo organization
This tutorial was written by Guillaume Autier, Sales Engineer, June 2009.