What is wrong with my snap yaml?

My snapcraft.yaml is:

name: dl 
base: core18
version: '0.1' 
summary: I
description: |
  Does stuff

grade: devel
confinement: devmode 
apps:
  certs:
    command: bash -c "sudo ${SNAP}/usr/lib/jvm/java-8-openjdk-${SNAP_ARCH}/bin/keytool -trustcacerts -keystore "${SNAP}/usr/lib/jvm/java-8-openjdk-${SNAP_ARCH}/jre/lib/security/cacerts" -noprompt -storepass changeit -importcert -alias spring -file $SNAP/bin/acert.crt"
    plugs: [unity7, network, home]
  ajar:
    command: bash -c "sudo ${SNAP}/usr/lib/jvm/java-8-openjdk-${SNAP_ARCH}/bin/java -Djavax.net.ssl.trustStore=${SNAP}/usr/lib/jvm/java-8-openjdk-${SNAP_ARCH}/jre/lib/security/cacerts -Djavax.net.ssl.trustStorePassword=changeit -jar ${SNAP}/bin/ajar.jar"
    daemon: simple
    plugs: [unity7, network, home]
    environment:
      JAVA_HOME: $SNAP/usr/lib/jvm/default-java
      PATH: $SNAP/usr/lib/jvm/default-java/bin:$PATH
  bjar:
    command: bash -c "${SNAP}/usr/lib/jvm/java-8-openjdk-${SNAP_ARCH}/bin/java -jar ${SNAP}/bin/bjar.war"
    daemon: simple
    plugs: [unity7, network, home]
    environment:
         JAVA_HOME: $SNAP/usr/lib/jvm/default-java
          PATH: $SNAP/usr/lib/jvm/default-java/bin:$PATH 
       
parts:    
  certs:
    plugin: nil
    stage-packages: [openjdk-8-jre, openjdk-8-demo]
    override-build: |
      set -x
      snapcraftctl build
      mkdir -p $SNAPCRAFT_PART_INSTALL/bin
      wget -c "https://drive.google.com/uc?export=download&id=anid" -O acert.crt
      cp -r acert.crt $SNAPCRAFT_PART_INSTALL/bin/.
           
  ajar:
    plugin: nil
    stage-packages: [openjdk-8-jre, openjdk-8-demo]
    after: [certs]
    override-build: |
      set -x
      snapcraftctl build
      wget -c "https://drive.google.com/uc?export=download&id=anotherid" -O ajar.jar
      mkdir -p $SNAPCRAFT_PART_INSTALL/bin
      cp -r ajar.jar $SNAPCRAFT_PART_INSTALL/bin/.
      chmod +x $SNAPCRAFT_PART_INSTALL/bin/ajar.jar
         
  bjar:
    plugin: nil
    stage-packages: [openjdk-8-jre, openjdk-8-demo]
    override-build: |
      set -x
      snapcraftctl build
      fileid="athirdid"
      filename="bjar.war"
      curl -c ./cookie -s -L "https://drive.google.com/uc?export=download&id=${fileid}" > /dev/null
      curl -Lb ./cookie "https://drive.google.com/uc?export=download&confirm=`awk '/download/ {print $NF}' ./cookie`&id=${fileid}" -o ${filename}
      mkdir -p $SNAPCRAFT_PART_INSTALL/bin
      cp -r bjar.war $SNAPCRAFT_PART_INSTALL/bin/.
      chmod +x $SNAPCRAFT_PART_INSTALL/bin/*

when I install it, bjar and certs can be seen using ps -fC java but not ajar. If I run the wrapper command setting SNAP and SNAP_ARCH environment variables ajar works. If I simplify the ajar in the above to:

command: bash -c "sudo ${SNAP}/usr/lib/jvm/java-8-openjdk-${SNAP_ARCH}/bin/java  -jar ${SNAP}/bin/ajar.jar"

It works but cannot see the crt. And I think ps -fC java does not show the certs step.

Any pointers on what am I doing wrong?

could you clean up the yaml you’ve pasted so it’s complete and readable?

For readability, before the yaml starts write a new line with just three backticks and the word ‘yaml’, like so:

```yaml

and then where the yaml ends, add a new line with just three bacticks in it,

```

that will make the yaml a lot more readable, like so:

project: snapd

environment:
    GOHOME: /home/gopath
    GOPATH: $GOHOME
    REUSE_PROJECT: "$(HOST: echo \"$REUSE_PROJECT\")"
    # etc

I could’ve added these little things myself, being a moderator, but there is also a chunk missing or mis-pasted, so it didn’t make sense even with these things added.

1 Like

I have done so. Does it look OK to you now?

I would be careful with this:

environment:
    JAVA_HOME: $SNAP/usr/lib/jvm/default-java

Apt likes to install openjre 11 as a default java runtime environment. I had a situation where I was running an app with an openjdk-8-jdk version of java, but other bits were running with JRE 11 unbeknownst to me. Nothing was failing outright, but things weren’t working as I expected.

I wonder if setting JAVA_HOME explicitly might be having unintended side effects. Purely a guess, of course.