当前位置: 首页 > news >正文

将jar包制作成deb一键安装包

文章目录

  • 准备环境
  • 准备deb包结构
  • 构建Deb包
  • 测试安装
  • 常用操作命令

本文介绍如何将java运行环境、jar程序一起打包成一个deb格式的安装包,创建桌面图标,通过点击图标可使用系统自带浏览器快捷访问web服务的URL,同时注册服务并配置好开机自启。

准备环境

  • 对应linux内核版本的debian或ubuntu或deepin环境虚拟机
  • jar包
  • 对应版本的java安装包

准备deb包结构

  1. 创建项目目录结构,debian目录即为用来打包的目录
mkdir debpackage
cd debpackage
mkdir -p debian/usr/share/helloapp
mkdir -p debian/usr/share/applications
mkdir -p debian/etc/systemd/system
mkdir -p debian/DEBIAN
  1. 将 java 运行环境 jre 目录拷贝到 debian/usr/share/helloapp 目录

  2. 将 jar包拷贝到 debian/usr/share/helloapp 目录下

  3. 将应用图标文件 icon.png 拷贝到 debian/usr/share/helloapp 目录下

  4. 创建启动脚本

vi debian/usr/share/helloapp/start.sh

#!/bin/bash
JAVA_HOME=/usr/share/helloapp/jre
$JAVA_HOME/bin/java -jar /usr/share/helloapp/helloword.jar
chmod +x debian/usr/share/helloapp/start.sh
  1. 创建systemd服务文件
vi debian/etc/systemd/system/helloapp.service

[Unit]
Description=小工具
After=network.target

[Service]
ExecStart=/usr/share/helloapp/start.sh
WorkingDirectory=/usr/share/helloapp
Restart=always

[Install]
WantedBy=multi-user.target
  1. 创建桌面快捷方式
vi debian/usr/share/applications/helloapp.desktop

[Desktop Entry]
Version=1.0
Categories=Application
Name=helloapp
Comment=myapp
Encoding=UTF-8
Exec=/usr/share/helloapp/start.sh
Icon=/usr/share/helloapp/img/icon.png
StartupNotify=true
Terminal=false
Type=Application
X-Deepin-Vendor=user-custom
  • 如果应用使用浏览器访问URL,则修改该文件,用浏览器打开URL:
[Desktop Entry]
Version=1.0
Name=helloapp
Name[zh_CN]=小工具
Type=Application
Encoding=UTF-8
Comment=Open My Java Application in Browser
Exec=xdg-open http://127.0.0.1:13099
Icon=/usr/share/helloapp/icon.png
StartupNotify=true
Terminal=false
X-Deepin-Vendor=user-custom
Categories=Network;WebBrowser;
  • 想用特定浏览器(如 Chrome/Firefox),修改 .desktop 文件,并添加对应浏览器到 Depends(如 google-chrome-stable)。
Exec=google-chrome http://127.0.0.1:13099
或
Exec=firefox http://127.0.0.1:13099
  1. 创建Debian控制文件
vi debian/DEBIAN/control

Package: helloapp
Version: 1.0
Section: utils
Priority: optional
Architecture: all
Depends: xdg-utils
Maintainer: Aaron
Description: java小工具
 
  • Architecture: all:适用于所有架构(纯脚本/URL启动),amd64
  • Depends: xdg-utils:确保 xdg-open 可用(用于打开浏览器)
  1. 创建安装后处理脚本
vi debian/DEBIAN/postinst

#!/bin/sh
# Enable and start the service
systemctl daemon-reload
systemctl enable helloapp.service
systemctl start helloapp.service

# Update desktop database
update-desktop-database /usr/share/applications

exit 0
chmod +x debian/DEBIAN/postinst
  1. 创建卸载前处理脚本
vi debian/DEBIAN/prerm

#!/bin/sh
# Stop and disable the service
systemctl stop helloapp.service
systemctl disable helloapp.service

exit 0
chmod +x debian/DEBIAN/prerm

构建Deb包

chmod -R 775 debian

dpkg-deb -b debian helloapp_1.0_arm.deb

测试安装

dpkg -i helloapp_1.0_arm.deb

常用操作命令

dpkg --list
dpkg-query -l
dpkg -r helloapp

# 列出特定软件包的详细信息
dpkg -L helloapp

dpkg -s helloapp

apt list helloapp

报错:(未解决,在debian虚拟机上安装报错,但是在银河麒麟系统上安装正常)

Error in file "/usr/share/applications/evince.desktop": "" is an invalid MIME type ("" does not contain a subtype)
http://www.dtcms.com/a/121988.html

相关文章:

  • 从 Excel 到你的表格应用:条件格式功能的嵌入实践指南
  • 【机密计算顶会解读】13:CAGE:通过 GPU 扩展补充 Arm CCA
  • 2025年3月全国青少年软件编程等级考试(Python五级)试卷及答案
  • 图解Java设计模式
  • 005.Gitlab CICD变量使用
  • oauth2.0认证原理
  • word表格间隔设置
  • C++20 数学常数:<numbers> 头文件的革新
  • cmd清除网络共享连接凭证
  • C++高精度算法(加、减、乘)
  • 【C++】 —— 笔试刷题day_13
  • 抽象类及其特性
  • cpp(c++)win 10编译GDAL、PROJ、SQLite3、curl、libtiff
  • Easysearch VS Opensearch 数据写入与存储性能对比
  • HOW - 实现 useClickOutside 或者 useClickAway
  • 大模型本地部署系列(1) Ollama的安装与配置
  • 神经网络 | 基于脉冲耦合神经网络PCNN图像特征提取与匹配(附matlab代码)
  • 408 计算机网络 知识点记忆(6)
  • Elasticsearch DSL 中的 aggs 聚合分析
  • 数据结构实验3.3:求解迷宫路径问题
  • 西门子S7-1500与S7-200SMART通讯全攻略:从基础配置到远程IO集成
  • SQL注入(SQL Injection)
  • Ollama 与 llama.cpp 深度对比
  • [特殊字符]【高并发实战】Java Socket + 线程池实现高性能文件上传服务器(附完整源码)[特殊字符]
  • 虽然理解git命令,但是我选择vscode插件!
  • Databricks: Why did your cluster disappear?
  • 【UE5】RTS游戏的框选功能+行军线效果实现
  • Spring Boot 3.x 下 Spring Security 的执行流程、核心类和原理详解,结合用户描述的关键点展开说明,并以表格总结
  • WPF 绑定方式举例
  • LabVIEW 图像处理中常见的边缘检测算法