Stage packaging the oracle jdk

I am trying to snap an application for which i want oracle jdk as a stage package.
How do I install oracle jdk.?

For Openjdk, it is possible to do it in snapcraft.yaml file.
When I define it in this way,

             -  oracle-java8-installer

oracle jdk do not get installed, only empty folder is created.

How can I do this?

It should work exactly the same way. Can you show more details of what is happening? A sample snapcraft.yaml to reproduce the issue would be nice, and also a recursive listing of the stage directory (in a paste service, please, just the link here).


      - ca-certificates
      - ca-certificates-java
      - openjdk-8-jre-headless
      - openjdk-8-jdk

… instead of the oracle -installer package …
(i dont think there is a way to get oracle java from the ubuntu archive via the installer at all), you would have to pull it ahead of time from oracle and ship it in your package source tree if you have a java redistribution license from oracle)

That’s incorrect. The oracle-java8-installer deb is merely an empty-ish package with a post-install script which does the actual fetch and installation of the java runtime. This won’t work as a stage-package in snapcraft because stage-packages are dumped into the snap without running any pre- or post- install scripts.

1 Like

What can I do to install it then?

For what it’s worth, I maintain the OmegaT snap which uses the JDK. You can have a look at


Installing Oracle JRE or JDK 8 on Debian or Ubuntu Systems

Configure your system to use the latest version of [Oracle Java SE 8 JRE or JDK] (1.8u151minimum). Java 9 and later are not supported.

Note: After installing the JDK, you may need to set JAVA_HOME to your profile:

  • For shell or bash: export JAVA_HOME=path_to_java_home
  • For csh (C shell): setenv JAVA_HOME=path_to_java_home
  1. Check which version of the JDK your system is using:

java -version

If the OpenJDK is used, the results should look like:

openjdk version "1.8.0_242"
OpenJDK Runtime Environment (build 1.8.0_242-b09)
OpenJDK 64-Bit Server VM (build 25.242-b09, mixed mode)

If Oracle Java is used, the results should look like:

java version "1.8.0_241"
Java(TM) SE Runtime Environment (build 1.8.0_241-b07)
Java HotSpot(TM) 64-Bit Server VM (build 25.241-b07, mixed mode)
  1. If necessary, go to [Oracle Java SE Downloads] accept the license agreement, and download the installer for your distribution.

The Oracle JDK License has changed for releases starting April 16, 2019. See Java SE Development Kit 8 Downloads.

Note: If installing the Oracle JDK in a cloud environment, download the installer to your local client, and then use scp (secure copy) to transfer the file to your cloud machines.

  1. Make a directory for the JDK:

sudo mkdir -p /usr/lib/jvm

  1. Extract the tarball and install the JDK:

sudo tar zxvf jdk-version-linux-x64.tar.gz -C /usr/lib/jvm

The JDK files are installed into a directory called /usr/lib/jvm/jdk-8u_version.

  1. Tell the system that there’s a new Java version available:

sudo update-alternatives --install “/usr/bin/java” “java” “/usr/lib/jvm/jdk1.8.0_version/bin/java” 1

Note: If updating from a previous version that was removed manually, execute the above command twice, because you’ll get an error message the first time.

  1. Set the new JDK as the default:

sudo update-alternatives --set java /usr/lib/jvm/jdk1.8.0_version/bin/java

  1. Verify the version of the JRE or JDK:

java -version

java version "1.8.0_241"
Java(TM) SE Runtime Environment (build 1.8.0_241-b07)
Java HotSpot(TM) 64-Bit Server VM (build 25.241-b07, mixed mode)