6

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?

Queeg
  • 7,748
  • 1
  • 16
  • 42
kxygk
  • 148
  • 1
  • 10
  • were you looking for a `.dmg`? – Naman May 05 '20 at 12:16
  • 1
    No.. I didn't mention MacOS anywhere. This is AppImage – kxygk May 05 '20 at 12:23
  • https://en.wikipedia.org/wiki/AppImage – kxygk May 05 '20 at 12:23
  • Linux executable format.. That JPackage seems to be able to emit – kxygk May 05 '20 at 12:24
  • 5
    I may be wrong but jpackage's concept of 'app-image' isn't what you are looking for, ie it isn't an installable AppImage package. I think jpackage produces an app-image (a set of directories) that contains everything that can be packaged into an exe, deb, rpm etc. When you specify '--type app-image' I think you are asking for jpackage just to create an app-image set of directories and not create an installable package. See this for a discussion on making this clearer in jpackage in future: https://bugs.openjdk.java.net/browse/JDK-8225428 Or maybe I have got hold on the wrong end of the stick? – David Miller May 09 '20 at 14:26

2 Answers2

2

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.

Queeg
  • 7,748
  • 1
  • 16
  • 42
  • Have you actually managed to do this? Or is this theoretical? I'd appreciate some specifics for the last part of "take it from here..." Your answer doesn't add anything that David Miller hasn't said already – kxygk Jan 18 '22 at 17:21
1

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.

DuncG
  • 12,137
  • 2
  • 21
  • 33
  • Wait, so if you have a program that doesn't need to remember things between runs, can you generate a double-clickable .exe executable without an installer? I was actually asking about Ubuntu, but I thought this was impossible on Windows. From my last experiments, you get a folder full of files, not all bundled into one .exe – kxygk Jan 22 '22 at 13:38
  • Correct - there is very little point using `--type app-image` unless you need to edit the release structure before building the installer. On Windows you can do everything in one step using `--type exe`. For example see my [answer here](https://stackoverflow.com/questions/147181/how-can-i-convert-my-java-program-to-an-exe-file/67789213#67789213). – DuncG Jan 22 '22 at 14:05
  • So you'd install locally and then get the .exe file out from your "C:\Program Files\MyApp\". That's good to know. It's a bit goofy but I guess that works :)Thanks for looking into it – kxygk Jan 24 '22 at 03:41