Hello,
I have been trying to package my simple sample application as a snap for some hours. I got various errors, maybe somebody can help me to understand the mistakes I make
snapcraft.yaml:
name: test-app
version: dev
summary: TODO summary
description: TODO description
base: core22
grade: devel
confinement: devmode
parts:
app-jar:
source: ./build/libs/
source-type: local
plugin: dump
stage-packages:
- openjdk-17-jdk # TODO headless?
apps:
server:
command: $JAVA_HOME/bin/java -jar app.jar
environment:
JAVA_HOME: $SNAP/usr/lib/jvm/java-17-openjdk-amd64
PATH: $JAVA_HOME/bin:$PATH
output:
Launching instance...
Executed: skip pull app-jar (already ran)
Executed: skip overlay app-jar (already ran)
Executed: skip build app-jar (already ran)
Executed: skip stage app-jar (already ran)
Executed: skip prime app-jar (already ran)
Executed parts lifecycle
Generated snap metadata
Unable to determine library dependencies for 'usr/lib/jvm/java-17-openjdk-amd64/lib/libnio.so'
Unable to determine library dependencies for 'usr/lib/jvm/java-17-openjdk-amd64/lib/libsctp.so'
Cannot pack snap file: Command '['snap', 'pack', '--filename', 'test-app_dev_amd64.snap', '--compression', 'xz', PosixPath('/root/prime'), PosixPath('/root/project')]' returned non-zero exit status 1. (2023/01/09 16:17:11.345666 container.go:215: in snap "test-app": path "$JAVA_HOME" does not exist
2023/01/09 16:17:11.345698 container.go:215: in snap "test-app": path "$JAVA_HOME/bin/java" does not exist
2023/01/09 16:17:11.345702 container.go:215: in snap "test-app": path "$JAVA_HOME/bin" does not exist
error: cannot pack "/root/prime": snap is unusable due to missing files)
Failed to execute pack in instance.
Full execution log: '/home/norbi/.cache/snapcraft/log/snapcraft-20230109-171657.121156.log'
You are already putting $JAVA_HOME into your $PATH in the environment block, so just remove $JAVA_HOME/bin/ from your command: entry and you should be good
That smells like a snapcraft bug to me, it might be a bit too strict with its checks and not take the PATH from environment into account during build… @sergiusens, @cmatsuoka couldn’t handling that be added to the checks in snapcraft?
Unable to determine library dependencies for 'usr/lib/jvm/java-17-openjdk-amd64/lib/libnio.so'
Unable to determine library dependencies for 'usr/lib/jvm/java-17-openjdk-amd64/lib/libsctp.so'
Maybe there is a connection between these messages and my problem?
Thanks, with the suggested modification the build works: command: /usr/lib/jvm/java-17-openjdk-amd64/bin/java -jar app.jar
Now I get Error: Unable to access jarfile app.jar when executing the snap command, and the same error when using the absolute path of app.jar: command: /usr/lib/jvm/java-17-openjdk-amd64/bin/java -jar /app.jar
The snap contains the file when I list the contents using unsquashfs:
...
squashfs-root/app.jar
OMG, I’ve read that it is not easy to get started with Snapcraft but I didn’t think that I cannot create a simple helloworld-level snap in hours
snapd will execute it in context of $SNAP then and should find the command just fine.
if you keep the slash as you did, it will actually try to find /usr/lib/jvm/… inside your base snap (which is your / at execution time of your snap) and indeed fail since the core22 snap does not ship java
regarding finding app.jar, here you might need to use $SNAP/app.jar …
It works! Thanks a lot!
Now I have to read the documentation more throughly because this system is more complex than it first seems (from a user’s perspective)