kxygk
kxygk

Reputation: 157

Using JPackage to make an 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?

Upvotes: 7

Views: 4451

Answers (2)

queeg
queeg

Reputation: 9372

While AppImage is a desireable format it is not (yet) supported by JPackage. Although 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.

Upvotes: 5

DuncG
DuncG

Reputation: 15086

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.

Upvotes: 0

Related Questions