Bundling openjdk-11-jdk into a snap

I am having trouble bundling openjdk-11-jdk (or openjdk-11-jre) into my snap.
I added it to the stage-packages section and it is indeed installed, however, it seems the update-alternatives command is not executed when installing it. Therefore the /usr/bin/java, usr/bin/javac, etc. soft links are not created and my application is unable to start java (command not found). I am not sure how to best work around this problem. Shall I create the soft links manually somewhere in my build process or shall I call sudo update-alternatives at some point to do it? Any better option?

Take a look at how we did this in the jenkins snap. We move directories around to make them non-arch specific, and put the cacerts file in the right place. It’s not super pretty, but it works, and means we can build for any supported architecture too.

That didn’t work for me. I ended up with a different solution:

  JAVA_HOME: "$SNAP/usr/lib/jvm/java-11-openjdk-amd64"

That works nicely and looks pretty clean.

The only flaw with that is it’ll only work on amd64 systems. That’s fine if you only want to support that architecture, but I needed to support multiple architectures.