Failed to generate snap metadata: The specified command defined in the app does not exist or is not executable

Hi everyone! I have the next snapcraft.yaml file (Java application, my first experience with snapcraft).

name: deletebg
base: core18
version: '0.3'
summary: Program for removing background in a photo
description: Delete Background is a professional image editing service for online retailers, photographers and designers.
grade: devel
confinement: devmode

apps:
  deletebg:
    environment:
      JAVA_HOME: $SNAP/usr/lib/jvm/java-11-openjdk-amd64
      PATH: $JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
    command: bin/deletebg
    plugs: [desktop, home, camera, x11, desktop-legacy, opengl, alsa, pulseaudio]

parts:
  deletebg:
    source: .
    plugin: maven
    source-type: local
    stage-packages: [openjdk-11-jre-headless]

And while Priming process, its show me an error:

Staging deletebg
Priming deletebg
Sorry, an error occurred in Snapcraft:
Traceback (most recent call last):
File “/usr/bin/snapcraft”, line 11, in
load_entry_point(‘snapcraft==2.43.1+18.4.1’, ‘console_scripts’, ‘snapcraft’)()
File “/usr/lib/python3/dist-packages/click/core.py”, line 722, in call
return self.main(*args, **kwargs)
File “/usr/lib/python3/dist-packages/click/core.py”, line 697, in main
rv = self.invoke(ctx)
File “/usr/lib/python3/dist-packages/click/core.py”, line 1043, in invoke
return Command.invoke(self, ctx)
File “/usr/lib/python3/dist-packages/click/core.py”, line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File “/usr/lib/python3/dist-packages/click/core.py”, line 535, in invoke
return callback(*args, **kwargs)
File “/usr/lib/python3/dist-packages/click/decorators.py”, line 17, in new_func
return f(get_current_context(), *args, **kwargs)
File “/usr/lib/python3/dist-packages/snapcraft/cli/_runner.py”, line 93, in run
ctx.forward(lifecyclecli.commands[“snap”])
File “/usr/lib/python3/dist-packages/click/core.py”, line 553, in forward
return self.invoke(cmd, **kwargs)
File “/usr/lib/python3/dist-packages/click/core.py”, line 535, in invoke
return callback(*args, **kwargs)
File “/usr/lib/python3/dist-packages/snapcraft/cli/lifecycle.py”, line 136, in snap
project = _execute(steps.PRIME, parts=[], **kwargs)
File “/usr/lib/python3/dist-packages/snapcraft/cli/lifecycle.py”, line 35, in _execute
lifecycle.execute(step, project_config, parts)
File “/usr/lib/python3/dist-packages/snapcraft/internal/lifecycle/_runner.py”, line 90, in execute
executor.run(step, part_names)
File “/usr/lib/python3/dist-packages/snapcraft/internal/lifecycle/_runner.py”, line 196, in run
self._create_meta(step, processed_part_names)
File “/usr/lib/python3/dist-packages/snapcraft/internal/lifecycle/_runner.py”, line 359, in _create_meta
self.config.validator.schema,
File “/usr/lib/python3/dist-packages/snapcraft/internal/meta/_snap_packaging.py”, line 109, in create_snap_packaging
packaging.write_snap_yaml()
File “/usr/lib/python3/dist-packages/snapcraft/internal/meta/_snap_packaging.py”, line 313, in write_snap_yaml
snap_yaml = self._compose_snap_yaml()
File “/usr/lib/python3/dist-packages/snapcraft/internal/meta/_snap_packaging.py”, line 517, in _compose_snap_yaml
snap_yaml[“apps”] = self._wrap_apps(self._config_data[“apps”])
File “/usr/lib/python3/dist-packages/snapcraft/internal/meta/_snap_packaging.py”, line 624, in _wrap_apps
self._wrap_app(app, apps[app])
File “/usr/lib/python3/dist-packages/snapcraft/internal/meta/_snap_packaging.py”, line 632, in _wrap_app
app[k] = self._wrap_exe(app[k], “{}-{}”.format(k, name))
File “/usr/lib/python3/dist-packages/snapcraft/internal/meta/_snap_packaging.py”, line 603, in _wrap_exe
with open(exepath, “rb”) as exefile:
FileNotFoundError: [Errno 2] No such file or directory: ‘/home/roman/IdeaProjects/deletebg.top-java/prime/bin/deletebg’
We would appreciate it if you created a bug report at
https://launchpad.net/snapcraft/+filebug with the above text included.

I did as explained in this tutorial.
What did I wrong?

run snapcraft with the --debug option so you get a shell after the error and take a look at the prime/ directory, where exactly your deletebg binary is … then adjust the command: entry accordingly

The shell didn’t appear. I got the same error

First, you’re using a very old version of Snapcraft, and it looks like you installed it via your system’s package manager instead of as a snap package. I recommend removing the copy of Snapcraft you installed and then install snapcraft via snap - the old version of Snapcraft is why the --debug flag didn’t start a shell:

sudo snap install snapcraft --classic

Second, once you have an up-to-date Snapcraft, you can retry what @ogra suggested and using the new subshell find the executable for your app in the prime directory to amend the command entry for your app:

snapcraft --debug
3 Likes

So, I removed the apt’s snapcraft and installed with snap.
I recreated the snapcraft.yaml with the next content:

name: deletebg
base: core18
version: '0.1'
summary: Single-line elevator pitch for your amazing snap
description: |
  This is my-snap's description. You have a paragraph or two to tell the
  most important story about your snap. Keep it under 100 words though,
  we live in tweetspace and your description wants to look good in the snap
  store.

grade: devel
confinement: devmode

parts:
  deletebg:
    plugin: maven
    source: .
    build-packages:
      - openjdk-11-jre-headless
      - openjfx

apps:
  deletebg:
    command: bin/deletebg

As snapcraft was run I got the new issue:

[Errno 17] File exists: ‘…/usr/lib/jvm/java-11-openjdk-amd64/bin/java’ -> ‘/root/parts/deletebg/install/bin/java’
We would appreciate it if you anonymously reported this issue.
No other data than the traceback and the version of snapcraft in use will be sent.
Would you like to send this error data? (Yes/No/Always/View) [no]:

I opened the shell and look into prime folder and there was java binary instead my deletebg binary. I don’t understand why.

why ? the above one looked fine …

since this is a java application you want openjdk to be a stage-package so the interpreter needs to be shipped inside your snap … i’m not sure if it is needed during build though

ok. Without build-packages (and --debug mode) parameter I got the next:

Failed to generate snap metadata: The specified command ‘bin/deletebg’ defined in the app ‘deletebg’ does not exist.
Ensure that ‘bin/deletebg’ is installed with the correct path.

With --debug key I got the

[Errno 17] File exists: ‘…/usr/lib/jvm/java-11-openjdk-amd64/bin/java’ -> ‘/root/parts/deletebg/install/bin/java’
We would appreciate it if you anonymously reported this issue.
No other data than the traceback and the version of snapcraft in use will be sent.
Would you like to send this error data? (Yes/No/Always/View) [no]

After I opened the shell and looked into prime folder (now bin folder was created, interesting) and there is the java binary file instead my deletebg

it might help if you could post the whole build log to a pastebin and link it here … it looks like your maven build does something wrong but the error above is only the result of that …

Building log: pastebin

I am wathching the snapcraft guide and noting that the deletebg binary should be created even without apps tab

[WARNING] JAR will be empty - no content was marked for inclusion!
[INFO] Building jar: /root/parts/deletebg/build/target/deletebg-1.0.4.jar

if you build this manually (not in a snap), does it actually produce a deletebg binary ?

When I build the jar file manually by IDE tools, its working fine. But when I build the jar by Maven I get this warning

but does building manually with maven produce a working binary ?

It doesn’t. I guess that the pom.xml (Maven configuration file) has incorrect settings. I will try to fix it and then run snapcraft again

1 Like

Well, I have fix the pom.xml. Now the warning is not appears. But the deletebg binary still not creating in the .snap file

Hm, what if deletebg binary shouldn’t be created? :thinking: In this example user uses bin/java and I have it too. Interesting…

1 Like