Introduction
The ZK Framework is an open-source Java framework for building Rich Internet Application (RIAs) with a focus of simplicity and usability. This article will guide you through the process of setting up the ZK Framework on a Red Hat Enterprise Linux (RHEL) system.
Table of Contents
IntroductionTable of ContentsPrerequisitesStep 1: Install JDKStep 2: Install Apache MavenStep 3: Install Apache TomcatStep 4: Create a ZK ProjectStep 5: Deploy the ZK ApplicationStep 6: Access Your ZK ApplicationConclusion
Prerequisites
Ensure that you have a running instance of RHEL system.
Step 1: Install JDK
The Java Development Kit (JDK) is a software development kit (SDK) that provides tools for building, testing, and running Java applications. We need this JDK available on our RHEL system since ZK Framework is built on Java.
- Install the JDK
 
Open a terminal on your RHEL machine, then update the yum package index.
sudo yum update -y
Install the JDK (OpenJDK 11 in this guide).
sudo yum install java-11-openjdk-devel-11.0.20.1.1-2.el9.x86_64
- Configure Environment Variable
 
You may want to set the 
JAVA_HOME environment variable. Open your .bashrc or .bash_profile file:vim ~/.bashrc
Add the following line at the end of the file:
export JAVA_HOME=$(dirname $(dirname $(readlink -f $(which java))))
Save the file and apply the changes:
source ~/.bashrc
- Verify the Installation and Configuration
 
echo $JAVA_HOME java -version
You should see the output indicating the version of Java installed like below.
Step 2: Install Apache Maven
Maven is build automation tool used for Java projects. 
- Install Maven using Yum
 
sudo yum install maven
- Configure Environment Variables
 
Set the 
MAVEN_HOME environment variable in the same way as for JDK.vim ~/.bashrc
Add the following lines.
export MAVEN_HOME=/usr/share/maven export PATH=$MAVEN_HOME/bin:$PATH
Save the file and apply the changes:
source ~/.bashrc
- Verify the Maven Installation
 
echo $MAVEN_HOME mvn -v
You should see the output indicating the version Maven look like below.
Step 3: Install Apache Tomcat
Apache Tomcat is an open-source web server and servlet. It is used widely for hosting Java-based applications on the web. 
- Download and Extract Tomcat
 
Navigate to the Tomcat download page at Apache Tomcat and copy the link to the latest version of Tomcat tar file. You can use the following command to download the current latest version (9.0.96) or replace it with version available.
wget https://downloads.apache.org/tomcat/tomcat-9/v9.0.96/bin/apache-tomcat-9.0.96.tar.gz
Extract the downloaded archive.
tar -xvzf apache-tomcat-9.0.96.tar.gz
Move the extracted directory to 
/opt :sudo mv apache-tomcat-9.0.96 /opt/tomcat
- Set the appropriate permissions for the Tomcat directory.
 
sudo chown -R tomcat:tomcat /opt/tomcat
- Navigate to the Tomcat 
bindirectory and start Tomcat: 
cd /opt/tomcat/apache-tomcat-9.0.96/bin ./startup.sh
Then, verify the installation by accessing Tomcat in your web browser.
http://localhost:8080
You should see the Tomcat welcome page.
- Create the Service File
 
Create symbolic link on 
/opt/tomcat . This way we can keep multiple version of Tomcat available on the system and refer to active on using /opt/tomcat/updated directory link.sudo ln -s /opt/tomcat/apache-tomcat-9.0.96 /opt/tomcat/updated
Open a new service file for Tomcat in the 
/etc/systemd/system/ directory.sudo vim /etc/systemd/system/tomcat.service
Add the following configuration to the file:
[Unit] Description=Apache Tomcat Web Application Container After=network.target [Service] Type=forking Environment=JAVA_HOME=/usr/lib/jvm/java-11-openjdk-11.0.20.1.1-2.el9.x86_64 Environment=CATALINA_PID=/opt/tomcat/updated/temp/tomcat.pid Environment=CATALINA_Home=/opt/tomcat/updated Environment=CATALINA_BASE=/opt/tomcat/updated Environment=’CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC’ Environment=’JAVA_OPTS.awt.headless=true -Djava.security.egd=file:/dev/v/urandom’ ExecStart=/opt/tomcat/updated/bin/startup.sh ExecStop=/opt/tomcat/updated/bin/shutdown.sh User=tomcat Group=tomcat UMask=0007 RestartSec=10 Restart=always [Install] WantedBy=multi-user.target
Reload the systemd daemon to recognize the new service:
sudo systemctl daemon-reload
Start the Tomcat service
sudo systemctl start tomcat
If all works correctly, you should see the service status to be active (running) and you can test again to 
localhost:8080 .If your the Tomcat not running, you can check the logs on 
/opt/tomcat/updated/logs/catalina.out . If you encounter BindExeption: Address already in use, consider kill the process that already use the port 8080 or change the Tomcat port. 
For killing the process run:
sudo ss -lptn 'sport = :8080' sudo kill -9 <pid>
For changing the Tomcat port, open 
/opt/tomcat/updated/conf/server.xml and find this part:<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" maxParameterCount="1000" />
Change the default port 
8080 to any other that not being use.Step 4: Create a ZK Project
- Create a New ZK Project
 
Navigate to your preferred workspace directory:
cd ~
Use Maven to create a new ZK project:
mvn archetype:generate -DgroupId=com.example.zk -DartifactId=my-zk-app -DarchetypeGroupId=org.zkoss -DarchetypeArtifactId=zk-archetype-webapp -DarchetypeVersion=9.6.0 -DinteractiveMode=false
Change into the project directory:
cd my-zk-app
Build the project.
mvn clean package
This will create a 
my-zk-app.war file in the target directory.Step 5: Deploy the ZK Application
- Copy the WAR file to the tomcat 
webappsdirectory 
cp target/my-zk-app.war /opt/tomcat/updated/webapps
- Start Tomcat
 
sudo systemctl start tomcat
- Verify the Tomcat is running
 
sudo systemctl status tomcat
- View Tomcat Logs
 
If you encounter issues, view the logs:
cat cat /opt/tomcat/updated/logs/catalina.out
Step 6: Access Your ZK Application
Open your web browser and navigate to:
http://localhost:8080/my-zk-app
You should see the default ZK application running successfully.
Conclusion
You’ve successfully created a ZK project using Maven, deployed it on Tomcat, and accessed it in your web browser. 
