Azul JRE bundled with my snap

Hi all,
I’m new to snap and trying to create a snapcraft.yaml for my Java cli tool.
I’m using the Azul JDK/JRE.

I have 2 questions:

  1. I have already a pipline process that build the Jar and place it in an artifactory. Is it possible to create a snap without building the app from source, but instead using the already existing Jar?
  2. How can I bundle in my snap the Azul jre version and based on it when the snap installed?

Additionally, I looked at the first snap java example, and I can’t see that the jre is included in the snap? the idea is to bring all the dependencies with the snap right? so the client wont need to install all the prerequisites by himself. So I expected to bring the jre bundled in the snap and when the snap is installed to use it to run the jar, somthing like “<SNAP_FS>/jre/bin/jar myjar.jar”

Thanks!

Ok, so did some progress:
this is my snapcraft.yaml

name: my-cli
version: '1.0.602'
summary: |
  My CLI
description: |
  Some My CLI Description.

confinement: devmode

parts:
  jre:
    source-type: tar
    source: ./zulu11.33.10-sa-jre11.0.4-linux_x64.tar.gz
    plugin: dump
  my-cli:
    source-type: local
    source: ./my-cli-1.0.602.jar
    plugin: dump
apps:
  my-cli:
    command: $SNAP/zulu11.33.10-sa-jre11.0.4-linux_x64/bin/java -jar my-cli-1.0.602.jar

and I’m getting the following error: ‘my-cli-1.0.602.jar’ is not a directory

Please advice.

you want to include an actual jre and also run the app command through that cli …

...
my-cli:
...
  stage-packages:
    - openjdk-8-jdk
apps:
   my-cli:
     environment:
       JAVA_HOME: $SNAP/usr/lib/jvm/java-1.8.0-openjdk-amd64
       PATH: $JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
     command: $JAVA_HOME/jre/bin/java -jar my-cli-1.0.602.jar

Thanks @ogra,
but I want to use Azul jre and not the regular openjdk, that’s why I try to bundle the Azul jre using tar.gz.
Additionally, I’m trying to dump my already compiled jar file, but I’m keep getting ‘my-cli-1.0.602.jar’ is not a directory

Did some progress,

name: my-cli
version: '1.0.602'
summary: |
  My CLI
description: |
  Some My CLI Description.

confinement: devmode

parts:
  jre:
    source-type: tar
    source: ./jre-source/zulu11.33.10-sa-jre11.0.4-linux_x64.tar.gz
    plugin: dump
  my-cli:
    source-type: local
    source: ./my-cli-source
    plugin: dump
apps:
  my-cli:
    command: ./bin/java -jar ./my-cli-1.0.602.jar

After installing the snap and running my-cli I’m getting the following:
Unable to access jarfile ./my-cli-1.0.602.jar

running unsquashfs -l *.snap | grep jar resulting with squashfs-root/my-cli-1.0.602.jar

try:

    command: ./bin/java -jar $SNAP/my-cli-1.0.602.jar
1 Like

Worked! thanks @ogra !

Do you have any improvement advice/recommendation that you think I need to add or change in my snap?

work out the proper set of interfaces so you can switch from devmode to stirct :wink: