How do I run 2 jar files in one app

Hi,
I am new to his but I have got a snap to run a java jar. Is it possible for the same snap to run 2 possibly in different terminals? I have tried:

apps:
  test:
command: usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java -jar $SNAP/src/ajar.jar
plugs: [unity7, network, home]
environment:
    JAVA_HOME: $SNAP/usr/lib/jvm/default-java
    PATH: $SNAP/usr/lib/jvm/default-java/bin:$PATH
    
command: usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java -jar $SNAP/src/bjar.war
plugs: [unity7, network, home]
environment:
    JAVA_HOME: $SNAP/usr/lib/jvm/default-java
    PATH: $SNAP/usr/lib/jvm/default-java/bin:$PATH  

but that just runs bjar. I have also tried a single command with the two jars in qoutes separated by a semicolon, but that gave a file not found error.

Any help is much appreciated!

apps:
  foo:
    command: ...
    ...
  bar:
    command: ...
    ...

If the snap is called “foo” the commands will be foo and foo.bar.

Thanks, but I want one command that runs both.

In most cases when I need to do things like this I usually write a small script that starts both programs, include it inside the snap and points my command to that one. But considering that your example is simple with exactly the same environment you could probably do something like this:

command: "sh -c '$SNAP/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java -jar $SNAP/src/ajar.jar; $SNAP/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java -jar $SNAP/src/bjar.war'"

The command that is executed is now sh (shell) and it’s runs the two additional commands. You can inspect the generated scripts in /snap/my-snap-name/current/command-app-name.wrapper

Thanks. That indeed runs the first one but since they are both servers, once the server is running, execution waits at that point and never runs the second one.

Are the applications services intended to be executed in the background? If that’s the case the daemon keyword may be useful? I’m curious, what problem is you trying to solve? It the command intended to be executed/started interactively by a user, or?

They are background services that expose APIs. So they run, then the user can go to a URI (from there one service calls the other service).

I see, the “snap way” is to use the daemon keyword, like this:

apps:
  ajar:
    command: usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java -jar $SNAP/src/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: usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java -jar $SNAP/src/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 

These will start both services in the background, you can read about the options here: https://docs.snapcraft.io/snapcraft-app-and-service-metadata

An important note is that daemons is executed as root (but they are still confined), and not as the current user. So paths like $SNAP_DATA will point to /var/snap/... and not $HOME/snap.

I no longer get any apps and my app name gives: ‘not found’.

Ah. Does that kick them off when the snap is installed?

Yes, they are installed as services that are started in the background.

They are indeed! Thank you so much!!