英文:
Using JPackage to make an AppImage
问题
我正在尝试使用 JPackage 创建一个 AppImage(在使用 OpenJDK 14 的 Ubuntu 18.04 系统上)。
我找到的所有示例都是以下形式:
jpackage --type app-image --name myappimage --input target --main-jar myuberjar.jar --main-class myapplication.core --verbose
当我运行这个命令时,会在当前目录下生成一个名为 ./myappimage/
的目录,在 ./myappimage/bin/
目录中有一个可执行文件,我可以启动它来运行应用程序。但是整个内容并没有打包成一个我想要的 AppImage 文件。
我在哪里出错了?
英文:
I'm trying to create an AppImage using JPackage (On a Ubuntu 18.04 System using OpenJDK 14)
All the examples I find are of the form
jpackage --type app-image --name myappimage --input target --main-jar myuberjar.jar --main-class myapplication.core --verbose
When I run this I get a directory ./myappimage/
and in ./myappimage/bin/
there is an executable that I can launch to run the application. But the whole thing isn't bundled into one AppImage file as I'd like.
What am I missing here?
答案1
得分: 2
虽然 AppImage 是一种理想的格式,但目前尚未(尚)受到 JPackage 的支持。虽然 JPackage 文档 提到了一个命令行选项 app-image,但其含义是不同的:
--app-image 文件路径
预定义应用程序映像的位置,用于构建可安装包(绝对路径或相对于当前目录)。
请参阅 create-app-image 模式选项以创建应用程序映像。
因此,app-image 文件夹只是 JPackage 在将其转换为类似 deb/msi/dmg 的本地包之前,收集应用程序的所有组成部分的文件夹。因此,请不要被这两个不同但名称相似的概念所混淆。
您的最佳方法是使用 JPackage 来组装所需的一切(就像 app-image 的情况一样),然后使用 AppImage.org 提供的工具继续进行操作。更简洁地说:
告诉 JPackage 在创建了 app-image 之后退出,方法如下:
jpackage --type app-image --dest app-image ...
这将使您拥有在 app-image 目录中收集的所有所需文件。不,不是全部文件。对于我的 OpenJDK(版本 16.0.1+9-Ubuntu-120.04),JPackage 命令忘记创建启动器(*.desktop 文件),并且在将构建完成为 debian 包时,它也忘记安装该文件。查看我是如何解决这个问题的。
从这里开始,您需要按照 AppImage 打包指南 创建一个 AppDir 目录结构,然后最终调用打包器。我将 app-image 目录复制到 AppDir/usr,并在 AppDir 中创建了一些符号链接。还需要创建 .desktop 文件。最重要的是创建一个指向 AppDir/usr/bin/... 中可执行文件的符号链接 AppDir/AppRun
。符号链接的名称必须是 AppRun。
最后,按照手动打包指南运行 appimagetool。有关如何运行它的信息似乎只在README.md上。我最终得到了一个带有 .appimage 文件扩展名的可执行文件。
对该文件设置可执行权限并运行它。
英文:
While AppImage is a desireable format it is not (yet) supported by JPackage. While the JPackage Documentation mentions a command line option app-image, it's meaning is different:
--app-image file path
Location of the predefined application image that is used to build an installable package (absolute path or relative to the current directory).
See create-app-image mode options to create the application image.
So the app-image folder is just the folder where JPackage collects all the bits and pieces for an application before converting that into a native package like deb/msi/dmg. As a result, just do not get confused by the two different yet similarly named concepts.
Your best approach is to use JPackage to assemble everything required (as it is the case for app-image), then take it from there with the tools provided by AppImage.org. Getting more concise:
Tell JPackage to exit after having created the app-image like so:
jpackage --type app-image --dest app-image ...
This will leave you will all files you need collected in the app-image directory. No, not all of them. For my OpenJDK (build 16.0.1+9-Ubuntu-120.04) the JPackage command forgets to create the launcher (*.desktop file), and when finishing the build to a debian package it forgets to install that file. See how I got around that.
From here you need to follow the AppImage packaging guide to create an AppDir directory structure before ultimately calling the packager. I copied the app-image directory into AppDir/usr and created a few symlinks in AppDir. Also needed to create the .desktop file. Most important is a symlink AppDir/AppRun
pointing to the executable in AppDir/usr/bin/... The name of the symlink has to be AppRun.
Finally follow Manual packaging and run the appimagetool. Information how to run it seems only on the README.md. I ended up with an executable with file extension .appimage.
Set executable permissions on that file and run it.
答案2
得分: 1
你只需要在希望在 jpackage 构建安装程序之前修改安装目录内容作为第二步,或者希望在不制作安装图像的情况下运行或测试发布结构时,才真正需要使用 jpackage --type app-image
。
例如,在 Windows 上,我使用以下命令将 app-image
构建到本地目录:
jpackage --type app-image --dest jpackage.dir ...
然后,我将生成的 EXE 文件重命名为 SCR 文件,以便将可执行文件用作 Windows 屏幕保护程序。您可能需要进行其他更改。如果您希望以后节省时间,也可以通过启动 jpackage.dir\AppName\xyz[.exe]
或 jpackage.dir/AppName/xyz
来在 app-image
目录中测试应用程序。
最后,将最终的 jpackage 阶段应用于从修改后的 app-image 结构生成安装程序:
jpackage --app-image jpackage.dir/yourappname --type exe
在您的情况下,对于 --type
,请使用 pkg|dmg 或其他适用值。如果您不需要进行修改,请跳过 --type app-image
步骤,直接将应用程序打包到目标环境的存档格式中。
英文:
You only really need to use jpackage --type app-image
if you wish to modify the contents of the installation directory contents before jpackage builds the installer as second step, or if you wish to run or test the release structure without making installation image.
For example on Windows I use app-image
to local build directories as:
jpackage --type app-image --dest jpackage.dir ...
Then I rename the generated EXE as SCR files so that I can use the executables as Windows Screensavers. You may have other changes to make here. You may save time later if you also test the applications in the app-image directories by launching as jpackage.dir\AppName\xyz[.exe]
or jpackage.dir/AppName/xyz
Finally apply the final jpackage stage to generate an installer from the modified app-image structure:
jpackage --app-image jpackage.dir/yourappname --type exe
In your case use pkg|dmg or other suitable value for --type
. If you don't need to make modifications skip the --type app-image
step and package directly to the archive format for your target environment.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论