How to Install JasperReports on Ubuntu 22.04

how to install jasperreports on ubuntu 22.04

JasperReports is an open-source reporting platform for creating, distributing, and managing reports. It is a Java class library; web developers who build Java-based websites and need to add reporting capabilities to their applications would use this tool.

JasperReports can also be used for Java applications like Java EE or other web applications to generate dynamic content. In this tutorial, we will show you how to install Jasper Reports on Ubuntu 22.04.

Prerequisites

  • Ubuntu 22.04 with at least 4GB of RAM, 8GB of RAM is recommended
  • SSH root access or a regular system user with sudo privileges

Step 1. Login to the server

First, log in to your Ubuntu 22.04 server through SSH as the root user:

ssh root@IP_Address -p Port_number

You will need to replace ‘IP_Address‘ and ‘Port_number‘ with your server’s respective IP address and SSH port number. Additionally, replace ‘root’ with the username of the system user with sudo privileges.

You can check whether you have the proper Ubuntu version installed on your server with the following command:

# lsb_release -a

You should get this output:

No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 22.04.2 LTS
Release: 22.04
Codename: jammy

Before starting, you have to make sure that all Ubuntu OS packages installed on the server are up to date. You can do this by running the following commands:

# apt update -y

Step 2. Create a System User

There is an option to install Jasper Reports on an Ubuntu 22.04 machine without using the installer; we are going to install it manually. First, we need to install Tomcat, and we will install Tomcat under a new system user. Let’s execute the command below to add a new system user.

# useradd -r tomcat -m -d /opt/tomcat --shell /bin/bash

Step 3. Install MariaDB

Jasper Reports server supports PostgreSQL, MySQL/MariaDB, Oracle, DB2, and SQL servers. In this step, we will install the MariaDB server from the repository. To do this, simply run the following command:

# apt install mariadb-server

MariaDB will be up and running on an Ubuntu machine upon installation; now, let’s create a MySQL user with full privileges.

# mysql

While in the MySQL shell, run these commands to create a database user.

MariaDB [(none)]> grant all on *.* to master@localhost identified by 'm0d1fyth15';
MariaDB [(none)]> flush privileges;

Step 4. Install Tomcat

We created a new system user in the previous step. And now, we are going to install Tomcat in this step. But first, we need to install Java. Let’s run the command below to install default JDK version 11, which is available on the built-in Ubuntu 22.04 repositories by using the following command:

# apt install default-jdk unzip wget nano -y

When writing this tutorial, the latest stable Tomcat version to download is version 9.0.76. You can go to hand check if they release the more recent version. To proceed with the installation, let’s download the binary distribution file first.

# su - tomcat
$ wget https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.76/bin/apache-tomcat-9.0.76.tar.gz -O tomcat-9.0.76.tar.gz

Our user ‘tomcat’ home directory is /opt/tomcat, and the directory was created when we added that user. And, we will install Tomcat under this directory. Let’s extract the downloaded file now.

$ tar -xzvf tomcat-9.0.76.tar.gz -C /opt/tomcat --strip-components=1

Now, the directory /opt/tomcat contains all Tomcat files. You can verify this with this command.

$ ls -lh /opt/tomcat

The command will return an output like this:

tomcat@ubuntu22:~$ ls -lh /opt/tomcat/
total 12M
-rw-r----- 1 tomcat tomcat 20K Jun 5 07:17 BUILDING.txt
-rw-r----- 1 tomcat tomcat 6.1K Jun 5 07:17 CONTRIBUTING.md
-rw-r----- 1 tomcat tomcat 56K Jun 5 07:17 LICENSE
-rw-r----- 1 tomcat tomcat 2.3K Jun 5 07:17 NOTICE
-rw-r----- 1 tomcat tomcat 3.4K Jun 5 07:17 README.md
-rw-r----- 1 tomcat tomcat 6.8K Jun 5 07:17 RELEASE-NOTES
-rw-r----- 1 tomcat tomcat 17K Jun 5 07:17 RUNNING.txt
drwxr-x--- 2 tomcat tomcat 4.0K Jun 19 13:43 bin
drwx------ 2 tomcat tomcat 4.0K Jun 5 07:17 conf
drwxr-x--- 2 tomcat tomcat 4.0K Jun 19 13:43 lib
drwxr-x--- 2 tomcat tomcat 4.0K Jun 5 07:17 logs
drwxr-x--- 2 tomcat tomcat 4.0K Jun 19 13:43 temp
-rw-rw-r-- 1 tomcat tomcat 12M Jun 5 07:32 tomcat-9.0.76.tar.gz
drwxr-x--- 7 tomcat tomcat 4.0K Jun 5 07:17 webapps
drwxr-x--- 2 tomcat tomcat 4.0K Jun 5 07:17 work

Now, exit from user ‘tomcat’ and go back to the root or your sudo user.

$ exit

We need to create a systemd file to manage our Tomcat service. Let’s create systemd service file for Tomcat.

# nano /etc/systemd/system/tomcat.service

Paste the following into the systemd service file, then save it.

[Unit]
Description=Apache Tomcat
After=network.target

[Service]
Type=forking

User=tomcat
Group=tomcat

Environment=JAVA_HOME=/usr/lib/jvm/java-1.11.0-openjdk-amd64
Environment=CATALINA_PID=/opt/tomcat/tomcat.pid
Environment=CATALINA_HOME=/opt/tomcat
Environment=CATALINA_BASE=/opt/tomcat
Environment="CATALINA_OPTS=-Xms1024M -Xmx1024M -server -XX:+UseParallelGC"

ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/opt/tomcat/bin/shutdown.sh

ExecReload=/bin/kill $MAINPID
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

Save the file, exit from nano editor then reload systemd for changes to take effect.

# systemctl daemon-reload

At this point, we are not going to start Tomcat.

Step 5. Download and Deploy JasperReports

In this step, we will download the Jasper Reports server zipped file and install it manually. When writing this article, the latest available version is 8.2.0. You can check if they have the more recent version at https://sourceforge.net/projects/jasperserver/files/JasperServer/.

# su - tomcat
$ wget https://sourceforge.net/projects/jasperserver/files/JasperServer/JasperReports%20Server%20Community%20Edition%208.2.0/TIB_js-jrs-cp_8.2.0_bin.zip/download -O jasperreports_8.2.0.zip

Once downloaded, we can extract it directly.

$ unzip jasperreports_8.2.0.zip

Jasper Reports server supports PostgreSQL, MySQL, Oracle, DB2, and SQL servers. In this article, we are going to use MySQL (MariaDB), and we already installed it. To proceed with the Jasper Report configuration file, let’s copy the sample configuration file first.

Let’s copy /opt/jasperreports-server-cp-8.0.0-bin/buildomatic/sampe-conf/mysql.master_properties to buildomatic directory as default_master.properties

$ cp -a jasperreports-server-cp-8.2.0-bin/buildomatic/sample_conf/mysql_master.properties jasperreports-server-cp-8.2.0-bin/buildomatic/default_master.properties

Now, let’s edit jasperreports-server-cp-8.2.0-bin/buildomatic/default_master.properties

$ nano jasperreports-server-cp-8.2.0-bin/buildomatic/default_master.properties

Add the two lines below

CATALINA_HOME = /opt/tomcat
CATALINA_BASE = /opt/tomcat

Then, replace the database configuration part with the following, and make sure the username and database match with the one we created earlier.

dbHost=localhost
dbUsername=master
dbPassword=m0d1fyth15

And set encrypt to true.

encrypt = true

It should look like this:

CATALINA_HOME = /opt/tomcat
CATALINA_BASE = /opt/tomcat

dbHost=localhost
dbUsername=master
dbPassword=m0d1fyth15

encrypt = true

Save the file then exit.

Next, let’s enter the buildomatic directory and run the js-install-ce.sh executable file. Prior to running this executable file, make sure Tomcat is NOT running.

$ cd jasperreports-server-cp-8.2.0-bin/buildomatic/
$ ./js-install-ce.sh

This will create databases and deploy jasperserver in Tomcat.

Then, let’s edit /opt/tomcat/conf/catalina.policy file.

$ nano /opt/tomcat/conf/catalina.policy

Append the following into the file.

grant codeBase "file:/groovy/script" {
permission java.io.FilePermission "${catalina.home}${file.separator}webapps${file.separator}
jasperserver-pro${file.separator}WEB-INF${file.separator}classes${file.separator}-", "read";
permission java.io.FilePermission "${catalina.home}${file.separator}webapps${file.separator}
jasperserver-pro${file.separator}WEB-INF${file.separator}lib${file.separator}*", "read";
permission java.util.PropertyPermission "groovy.use.classvalue", "read";
};


Save the file then exit.

Then, we also need to edit applicationContext.xml file.

$ nano /opt/tomcat/webapps/jasperserver/WEB-INF/applicationContext.xml

Insert these into the reportsProtectionDomainProvider list.

    <bean class="java.io.FilePermission">
        <constructor-arg value="${catalina.home}${file.separator}webapps
        ${file.separator}jasperserver-pro${file.separator}
        WEB-INF${file.separator}classes${file.separator}-"/>
        <constructor-arg value="read"/>
    </bean>
    <bean class="java.io.FilePermission">
        <constructor-arg value="${catalina.home}${file.separator}webapps
        ${file.separator}jasperserver-pro${file.separator}WEB-INF
        ${file.separator}lib${file.separator}*"/>
        <constructor-arg value="read"/>
    </bean>

It should look like in the picture below.

Once completed, you can start Tomcat and wait for a few moments until everything is running.

$ exit
# systemctl start tomcat

Then, you can navigate to http://YOUR_SERVER_IP_ADDRESS:8080/jasperserver/ to access JasperReports Server using the default login credentials.

username: jasperadmin
password: jasperadmin

Once logged in, you can see the dashboard

Step 6. Install Nginx as A Reverse Proxy

Since Tomcat is running on its default port 8080, we need to configure a reverse proxy to be able to access it on port 80 or 443. In this step, we are going to install nginx and configure it as a reverse proxy to the Jasper Reports server.

Need a fast and easy fix?
✔ Unlimited Managed Support
✔ Supports Your Software
✔ 2 CPU Cores
✔ 2 GB RAM
✔ 50 GB PCIe4 NVMe Disk
✔ 1854 GeekBench Score
✔ Unmetered Data Transfer
NVME 2 VPS

Now just $43 .99
/mo

GET YOUR VPS
# apt install nginx

In Ubuntu 20.04, nginx will start running upon installation. Now, it’s time to create a server block for our Jasper Reports server.

# nano /etc/nginx/conf.d/jasperreports.conf

Insert the following configuration into the file. Make sure to use your actual domain or subdomain name.

upstream tomcat {
    server 127.0.0.1:8080 weight=100 max_fails=5 fail_timeout=5;
    }

server {
    server_name jasperreports.yourdomain.com;

location = / {
    return 301 http://jasperreports.yourdomain.com/jasperserver/;
    }

location / {
    proxy_set_header X-Forwarded-Host $host;
    proxy_set_header X-Forwarded-Server $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_pass http://tomcat/;
    }
}


Now, restart nginx service.

# systemctl restart nginx

Now, you should be able to access your JasperReports website at https://jasperreports.yourdomain.com.

That’s it all! You have successfully installed JasperReports Server on Ubuntu 22.04.

Of course, you don’t have to pull your hair to install JasperReports Server on Ubuntu 22.04 if you have a managed Linux VPS hosting plan hosted with us. If you do, you can simply ask our support team to install Jasper Reports Server on Ubuntu 22.04 for you. They are available 24/7 and will be able to help you with the installation of Jasper Reports as well as any additional requirements that you may have.

PS. If you enjoyed reading this blog post on how to install JasperReports Server on Ubuntu 22.04, feel free to share it on social networks or simply leave a comment in the comments section. Thank you.

Leave a Comment