JasperReports Server is a stand-alone and embeddable reporting server. In this tutorial we will see how to connect Jaspersoft Studio to JasperReports Server, and how to upload and download a report from the server.
Since we need to interact with JasperReports Server we need the server's URL and the credentials to access it. If you do not have both of these, you can install JasperReports Server locally. To do this, follow THIS link and download the correct version for your operating system, then install it following the on-screen instructions.
Connection to JasperReports Server
To have an easy-to-replicate example, suppose that we are using a local installation of JasperReports Server. To check if our server is running, open your browser and copy in the address bar this URL:
You should see a window like this:
Now you can start Jaspersoft Studio. Click the Repository Explorer tab, then select Create a JasperReports Server Connection.
A dialog to insert the server data appears. Fill it in as follows:
- Name: the name of the connection. You can use any name you want. For this example we will leave the default name: JasperReports Server.
- URL: the address of the server. The default address is already correct if we are using a local server. For this example the correct address is http://localhost:8080/jasperserver/services/repository.
- User: the username to access the server. The default for the local server is "jasperadmin".
- Password: as with the username, for the local server by default it is "jasperadmin".
Then click the Test Connection button to test the connection. If everything is working, click Finish.
Now you are connected to the server and you can upload and download reports.
Publishing a Report on JasperReports Server
For this section, we will use the one created during the tutorial Report Structure in Jaspersoft Studio. Open the report and click the button with a blue arrow in the upper-right corner of the designer. In the opened window you can browse the server directory structure to choose where to place the report. Select the Reports folder as in the image above. Name the report unit you are creating to contain all the files for the report we are uploading (for this example we can use "ColumnsSample"). Then click Next.
In the next step we have to handle the data source. Exporting a report is quite simple, but exporting the data source used to fill the report it isn't so trivial. For exporting the data source we have three options:
- Data source from repository: the server will use a data source already there it to fill the report, so we will only need to browse the server until we find the wanted data source.
- Local data source: This option is useful is we want to publish a Datasource which already exists in the Studio, to the Server. Further details in the following section.
- Don't use any data source: only the report is exported without any data source connection
We will use the third option, which is the default one, and click Finish. The report is uploaded to the server and, if there are no errors, an appropriate message will be shown.
Local data source details
As stated previously, this option is useful to publish a datasource which has been already defined in the studio to the JasperReports Server.
After selecting Local Datasource, you can select the kind of Datasource that you want to publish to th JasperReports Server, like jdbc.
After doing that, you will have to provide the name the Datasource will be having as a whithin the Report unit's folder, and after that, the next window will give you the possibility to select the Import from Jaspersoft Studio button, where you can pick any of the already defined Datasource, and as soon as you that, all the Datasource's details will be filled in and ready to be published on the JapserReport Server as well! Al you have to do is to press Finish and it's done.