Skip to main content

jpackage in Java 14

jpackage is a command-line tool to create native installers and packages for Java applications.

Install OpenJDK 14 on Ubuntu 20.04/18.04
curl -O https://download.java.net/java/GA/jdk14/076bab302c7b4508975440c56f6cc26a/36/GPL/openjdk-14_linux-x64_bin.tar.gz
tar xvf openjdk-14_linux-x64_bin.tar.gz
mv jdk-14 $HOME/opt/
Packing JAR as .deb
mkdir {icons,input,output,temp}

tree -L 3 --dirsfirst --filelimit 10 --sort=name
.
├── icons
│   └── CloudCoin_Wallet-Dark.png
├── input
│   └── CloudCoin.D.3.0.15.jar
├── output
│   ├── CloudCoin_Wallet-Dark
│   │   ├── bin
│   │   └── lib
│   └── cloudcoin-wallet-dark_3.0.15-1_amd64.deb
├── temp
├── build.sh
└── license.txt

7 directories, 5 files

檔案目錄說明:

  • icons: App 的圖示檔(*.png), size 256x256
  • input: 原始的 jar 檔
  • output: 封裝後的 .deb 檔案
  • temp: 封裝過程中會用到的暫存檔
  • build.sh: 封裝啟動檔
  • license.txt: App 的使用授權宣告

build.sh

export PATH="$PATH:~/opt/jdk-14/bin"

[ -d temp ] && rm -rf temp/*
jpackage \
--type deb \
--name CloudCoin_Wallet-Dark \
--description "CloudCoin Wallet - Dark Edition. Homepage: https//cloudcoin.global." \
--vendor "CloudCoin Consortium" \
--app-version 3.0.15 \
--input input --dest output --temp temp \
--icon icons/CloudCoin_Wallet-Dark.png \
--license-file license.txt \
--copyright "CloudCoin™ Global Consortium © 2020 The Future of Currency" \
--main-jar CloudCoin.D.3.0.15.jar \
--linux-deb-maintainer alang.hsu@gmail.com \
--linux-app-category misc \
--linux-shortcut
  • PATH:JDK 14 的安裝目錄,也就是 jpackage 的儲存目錄。
  • 第 3 行:每次封裝前,先清除目錄 temp。
  • --type:封裝檔的類型。
  • --name:應用程式名稱。
  • --description:應用程式更多描述。
  • --vendor:來源製造商。
  • --input:input 目錄路徑。
  • --dest:output 目錄路徑。
  • --temp:temp 目錄路徑。
  • --icon:App 圖示檔路徑。
  • --license-file:使用授權宣告檔。
  • --main-jar:原始 jar 檔名。
  • --linux-deb-maintainer:維護者名稱。
  • --linux-app-category:應用程式類型。
  • --linux-shortcut:建立應用程式啟動檔。