Skip to content

Instantly share code, notes, and snippets.

@jpret
Last active November 8, 2021 14:29
Show Gist options
  • Select an option

  • Save jpret/29f0c64a930aae7fa9a1bc726e344100 to your computer and use it in GitHub Desktop.

Select an option

Save jpret/29f0c64a930aae7fa9a1bc726e344100 to your computer and use it in GitHub Desktop.
Use jpackage to create an installer for Java application (which uses Maven)
# Java Package Example (jpex) project directory
# jpackage_example
# + src
# + main
# + java
# Main (This is the main class file for this example)
# + test
# // After a mvn package the target folder is available
# + target
# pom.xml
# From the project directory clean and build the jar files
mvn clean package
# Use jpackage to build the rpm installer
# input - target folder
# name - the name of the main executable
# main-jar the main jar file inside the input folder
# main-class if no manifest is created you should specify the main class as well
# There is a lot of options -> See the documentation, but below is sufficient
jpackage --input target --name jpex --main-jar jpex01.jar --main-class Main
# IMPORTANT - rpm-build is a pre-requisite to build a rpm package thus install it if you have not
sudo yum install rpm-build
# Once the rpm package is created you can install it as follows [ -i | --install ]
sudo rpm -i jpex-1.0-1.x86_64.rpm
# Uninstall is also quite easy [ -e | --erase ]
sudo rpm -e jpex-1.0-1.x86_64.rpm
# RPM packages also have pre- and post- install scripts which you can use to configure the program
# ...
# If you create a symlink as follows after installation:
sudo ln -s /opt/jpex/bin/jpex /usr/local/bin/jpex
# Then startup is as easy as
jpex
# And shutdown
pkill jpex
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment