I started working with Ubuntu Core and Snaps a few days ago. I've managed to finish the very basic tutorial about creating my own snap and everything worked perfect.

Now it's time to go further, so for bigger purposes I tried to create my own Hello World snap. My idea is to code a Java daemon for printing "hello world" right and backwards, using the StringUtils library just for the need of adding some maven dependencies, and downloading the code from a GitLab private repository.

The java code worked fine on my computer so I went for the snapcraft.yaml:

name: java-maven-hello
version: 0
summary: A java example using maven dependecies
description: this is not much more than an example
confinement: devmode
grade: devel

    command: java -cp basic-project-0.0.1-SNAPSHOT.jar es.ramadorp.odm.snapcraft.test.daemon.Daemontest
    restart-condition: always 
    daemon: forking

    plugin: maven
    source: http://gitlab.ramadorp.es/ramador/snap-maven-test.git

Time to run snapcraft and no problems so far, but when I try to install the delivered snap I get:

error: cannot perform the following tasks:
- Start snap "java-maven-hello" (unset) services ([start snap.java-maven-hello.daemon.service] failed with exit status 1: Job for snap.java-maven-hello.daemon.service failed because the control process exited with error code.

The "systemctl status snap.java-maven-hello.daemon.service" gives me:

● snap.java-maven-hello.daemon.service
   Loaded: not-found (Reason: No such file or directory)
   Active: failed (Result: timeout) since lun 2017-04-24 10:23:54 CEST; 4min 34s ago

abr 24 10:22:24 Bec systemd[1]: Starting Service for snap application java-maven-hello.daemon...
abr 24 10:22:24 Bec /usr/bin/snap[8670]: cmd.go:111: DEBUG: restarting into "/snap/core/current/usr/bin/snap"
abr 24 10:22:24 Bec snap[8670]: Error: Could not find or load main class es.ramadorp.odm.snapcraft.test.daemon.Daemontest
abr 24 10:22:24 Bec systemd[1]: snap.java-maven-hello.daemon.service: Control process exited, code=exited status=1
abr 24 10:23:54 Bec systemd[1]: snap.java-maven-hello.daemon.service: Start operation timed out. Terminating.
abr 24 10:23:54 Bec systemd[1]: Failed to start snap.java-maven-hello.daemon.service.
abr 24 10:23:54 Bec systemd[1]: snap.java-maven-hello.daemon.service: Unit entered failed state.
abr 24 10:23:54 Bec systemd[1]: snap.java-maven-hello.daemon.service: Failed with result 'timeout'.

So, I understand the installation is not finding the .jar to execute?, but I went deep on the folders created by snapcraft and the "basic-project-0.0.1-SNAPSHOT.jar" is there, in /home/bec_1/wkf/snapmaven/parts/daemon/build/target. My knowledge doesn't go much far to understand if the .jar location is right or why the installation is not finding the "main class". Any ideas? By the way, my pom.xml file looks like:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">


    <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->


You may need to specify the path to the jar file when launching it. Something like this:-

    command: java -cp $SNAP/basic-project-0.0.1-SNAPSHOT.jar es.ramadorp.odm.snapcraft.test.daemon.Daemontest
  • Thanks! now I can install the snap, but it's not working yet. I add the $SNAP like you said but I when I try to execute the snap I receive "command not found". Am I still pointing wrong? I also tried to add the route like: – java -cp $SNAP/home/bec_1/wkf/snapmaven/prime/jar/basic-project-0.0.1-SNAPSHOT.jar and more variations, just in case (trial and error), and nothing. – Poor-Man Apr 28 '17 at 11:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.