错误:无法找到或加载主类 - Spring Boot Application jar

时间:2017-11-15 08:51:44

标签: java spring spring-boot

我构建了一个Spring Boot应用程序,并将其作为jar部署到Ubuntu 16.04 LTS。

当我尝试使用

运行应用程序时

java -jar myapp.jar

它工作正常。

但是,在我创建一个systemd文件以将其作为服务运行后,我收到以下错误:

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'.

有人可以帮忙吗?感谢。

1 个答案:

答案 0 :(得分:5)

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

您缺少与您的工作命令相比的-jar参数。它应该是

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