1

I built a Spring Boot application and deployed it as a jar to Ubuntu 16.04 LTS.

When I try to run the application by using

java -jar myapp.jar

it works fine.

However, after I created a systemd file to run it as a service, I get the following error:

myapp.service - myapp
   Loaded: loaded (/etc/systemd/system/myapp.service; disabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Wed 2017-11-15 08:38:01 UTC; 18s ago
  Process: 5138 ExecStart=/usr/bin/java /var/myapp/myapp.jar (code=exited, status=1/FAILURE)
 Main PID: 5138 (code=exited, status=1/FAILURE)

Nov 15 08:38:01 ip-xxx-xx-xx-xx systemd[1]: Started myapp.
Nov 15 08:38:01 ip-xxx-xx-xx-xx java[5138]: Error: Could not find or load main class .var.myapp.myapp.jar
Nov 15 08:38:01 ip-xxx-xx-xx-xx systemd[1]: myapp.service: Main process exited, code=exited, status=1/FAILURE
Nov 15 08:38:01 ip-xxx-xx-xx-xx systemd[1]: myapp.service: Unit entered failed state.
Nov 15 08:38:01 ip-xxx-xx-xx-xx systemd[1]: myapp.service: Failed with result 'exit-code'.

Can someone please help? Thanks.

kovac
  • 4,945
  • 9
  • 47
  • 90
  • 2
    Possible duplicate of [What does "Could not find or load main class" mean?](https://stackoverflow.com/questions/18093928/what-does-could-not-find-or-load-main-class-mean) – Lokesh Pandey Nov 15 '17 at 08:53
  • Do you have the `-jar` option in your `systemd` file? – stdunbar Nov 15 '17 at 16:30

1 Answers1

5
ExecStart=/usr/bin/java /var/myapp/myapp.jar

You are missing -jar parameter comparing to Your working command. It should be

ExecStart=/usr/bin/java -jar /var/myapp/myapp.jar
cyprian
  • 351
  • 3
  • 8
  • My goodness... Was really scratching my head. Thank you so much. I will accept your answer shortly. – kovac Nov 15 '17 at 09:05