After reading the "building snap tutorial" and checking the documentation, other tutorials and some examples, I'm still confused about how the command section in the .yaml for the snaps works, or better said, how I can invoke the snap.
Some of the tutorials just use "command: example" and run the snap typing "example", other use "command: bin/example" or even "command: bin/example.sh".
I understand they are pointing at the folder where the executable file is located, so I did the same with my .yaml trying to reach and execute the jar who runs my daemon:
apps: daemon-test: command: java -cp $SNAP/basic-project-0.0.1-SNAPSHOT.jar es.ramadorp.odm.snapcraft.test.daemon.Daemontest restart-condition: always daemon: simpleBut when type "daemon-test" or "name-snap.daemon-test" I get the "command not found" prompt. Going further than solving my problem (which it'd great), I have some questions:
- Why the bin folder in "command"? is autogenerated by snapcraft? is it mandatory in some specific cases?
- Why sometimes you need a .sh and others just need to write a name for running the snap?
- When do you need to write just the word in command and when do you need to write the name-snap.command-word?
- When do you need to point to a "executable file" and when is not needed, just a word?
P.D: Am I pointing correctly to my executable jar? I also tried adding the route to the /prime/jar/ folder but nothing.
1 Answer
Strictly confined snaps are typically can't 'see' folders outside the snap itself, and some other locations. There are envionment variables which point to the most important ones.
When the snap is launched, the path is setup correctly for it to find binaries located in $SNAP/bin, however it won't see things outside the snap, like for example (in your case) the java runtime. In this instance you should bundle the relevant jvm for your application.
This could be achieved with:-
stage-packages: - openjdk-8-jre-headless
or by adding a part containing the Oracle JRE, unpacked and put in a relavent place. For example if you had a folder called jre1.8.0_112 containing the Oracle JRE you might have a part such as:-
jbidwatcher: plugin: dump source: ./ organize: 'jre1.8.0_112': usr/lib/jvm/
Then you could set export JAVA_HOME=$SNAP/usr/lib/jvm before execution of your program. You might also want to have a 'wrapper' script which gets dropped in $SNAP/bin which sets up the above and other environment variables required by your application. It could also contain the long command line, like this:-
apps: myjavaapp: command: $SNAP/usr/bin/launch_myjavaapp plugs: - network
With a line in the part above to put that script in the right place:-
jbidwatcher: plugin: dump source: ./ organize: 'jre1.8.0_112': usr/lib/jvm/ 'launch_myjavaapp': usr/bin/