Heroku 可执行 Jar 应用程序在几秒钟后崩溃
Heroku Executable Jar App Crashing After a Few Seconds
我正在尝试 运行 一个 Java Discord 机器人,我已将其编译到 Heroku 上的可执行 jar 中。当 运行 在我的机器上安装这个 jar 时,它会连续 运行s 而不会崩溃。
根据 the Heroku instructions for deploying an executable jar via CLI,我 运行 命令行命令:
heroku plugins:install java
heroku create storytelling-bot --no-remote --region eu
heroku deploy:jar StoryTellerBot.jar --app storytelling-bot
这些命令中的最后一个似乎引发了几个 Java 异常,但据我所知这些与我的 .jar 无关,看起来它们是临时文件的清理过程在我的机器上创建的进程出于任何原因无法访问:
remote: https://storytelling-bot.herokuapp.com/ deployed to Heroku
remote:
-----> Done
Exception in thread "Thread-0" java.lang.RuntimeException: Failed to delete C:\Users\Ben\AppData\Local\Temp\heroku-deploy3868081789627054304
at com.heroku.sdk.deploy.DeleteDirectoryRunnable.run(DeleteDirectoryRunnable.java:46)
at java.lang.Thread.run(Unknown Source)
Caused by: java.nio.file.FileSystemException: C:\Users\Ben\AppData\Local\Temp\heroku-deploy3868081789627054304\heroku\app\.heroku-deploy: The process cannot access the file because it is being used by another process.
at sun.nio.fs.WindowsException.translateToIOException(Unknown Source)
at sun.nio.fs.WindowsException.rethrowAsIOException(Unknown Source)
at sun.nio.fs.WindowsException.rethrowAsIOException(Unknown Source)
at sun.nio.fs.WindowsFileSystemProvider.implDelete(Unknown Source)
at sun.nio.fs.AbstractFileSystemProvider.delete(Unknown Source)
at java.nio.file.Files.delete(Unknown Source)
at com.heroku.sdk.deploy.DeleteDirectoryRunnable.visitFile(DeleteDirectoryRunnable.java:21)
at com.heroku.sdk.deploy.DeleteDirectoryRunnable.visitFile(DeleteDirectoryRunnable.java:16)
at java.nio.file.Files.walkFileTree(Unknown Source)
at java.nio.file.Files.walkFileTree(Unknown Source)
at com.heroku.sdk.deploy.DeleteDirectoryRunnable.run(DeleteDirectoryRunnable.java:44)
... 1 more
尽管存在异常,但 jar 运行 在 Heroku 上的运行时间略长于一分钟。分钟结束后,应用停止 运行ning。完整的 Heroku 日志,来自 运行ning
heroku logs --tail -a storytelling-bot
说:
2020-05-09T22:16:05.389817+00:00 app[api]: Initial release by user {my email}
2020-05-09T22:16:05.389817+00:00 app[api]: Release v1 created by user {my email}
2020-05-09T22:16:05.695884+00:00 app[api]: Enable Logplex by user {my email}
2020-05-09T22:16:05.695884+00:00 app[api]: Release v2 created by user {my email}
2020-05-09T22:21:29.000000+00:00 app[api]: Build started by user {my email}
2020-05-09T22:21:41.843885+00:00 app[api]: Scaled to web@1:Free by user {my email}
2020-05-09T22:21:41.824208+00:00 app[api]: Deploy by user {my email}
2020-05-09T22:21:41.824208+00:00 app[api]: Release v3 created by user {my email}
2020-05-09T22:21:42.000000+00:00 app[api]: Build succeeded
2020-05-09T22:21:47.570594+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will override them.
2020-05-09T22:21:47.574241+00:00 app[web.1]: Picked up JAVA_TOOL_OPTIONS: -Xmx300m -Xss512k -XX:CICompilerCount=2 -Dfile.encoding=UTF-8
2020-05-09T22:21:47.802707+00:00 app[web.1]: SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
2020-05-09T22:21:47.802709+00:00 app[web.1]: SLF4J: Defaulting to no-operation (NOP) logger implementation
2020-05-09T22:21:47.802709+00:00 app[web.1]: SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
2020-05-09T22:21:48.770049+00:00 app[web.1]: SLF4J: Failed to load class "org.slf4j.impl.StaticMDCBinder".
2020-05-09T22:21:48.770213+00:00 app[web.1]: SLF4J: Defaulting to no-operation MDCAdapter implementation.
2020-05-09T22:21:48.770431+00:00 app[web.1]: SLF4J: See http://www.slf4j.org/codes.html#no_static_mdc_binder for further details.
2020-05-09T22:21:48.934598+00:00 app[web.1]: [main] INFO JDA - Login Successful!
2020-05-09T22:21:49.283574+00:00 app[web.1]: [JDA MainWS-ReadThread] INFO WebSocketClient - Connected to WebSocket
2020-05-09T22:21:49.547755+00:00 app[web.1]: [JDA MainWS-ReadThread] INFO JDA - Finished Loading!
2020-05-09T22:23:16.058897+00:00 heroku[web.1]: State changed from starting to crashed
2020-05-09T22:23:16.132636+00:00 heroku[web.1]: State changed from crashed to starting
2020-05-09T22:23:20.713652+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will override them.
2020-05-09T22:23:20.717823+00:00 app[web.1]: Picked up JAVA_TOOL_OPTIONS: -Xmx300m -Xss512k -XX:CICompilerCount=2 -Dfile.encoding=UTF-8
2020-05-09T22:23:20.997244+00:00 app[web.1]: SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
2020-05-09T22:23:20.997305+00:00 app[web.1]: SLF4J: Defaulting to no-operation (NOP) logger implementation
2020-05-09T22:23:20.997385+00:00 app[web.1]: SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
2020-05-09T22:23:21.975791+00:00 app[web.1]: SLF4J: Failed to load class "org.slf4j.impl.StaticMDCBinder".
2020-05-09T22:23:21.975824+00:00 app[web.1]: SLF4J: Defaulting to no-operation MDCAdapter implementation.
2020-05-09T22:23:21.975921+00:00 app[web.1]: SLF4J: See http://www.slf4j.org/codes.html#no_static_mdc_binder for further details.
2020-05-09T22:23:22.118150+00:00 app[web.1]: [main] INFO JDA - Login Successful!
2020-05-09T22:23:22.462633+00:00 app[web.1]: [JDA MainWS-ReadThread] INFO WebSocketClient - Connected to WebSocket
2020-05-09T22:23:22.720617+00:00 app[web.1]: [JDA MainWS-ReadThread] INFO JDA - Finished Loading!
2020-05-09T22:24:49.394239+00:00 heroku[web.1]: State changed from starting to crashed
如日志所述,应用程序停止 运行ning。 (请注意,"failed to load class" 行与我在计算机上 运行 运行应用程序时得到的一致;它们不会导致应用程序终止。)
为什么 Jar 会这样崩溃?大概我的 Jar 或我的 Heroku 应用程序需要一些额外的设置才能正常工作——尽管这没有作为 Heroku 通过 CLI 设置可执行 Jar 的指南的一部分提及。
你没有提供太多信息你在你的应用程序中实际做了什么,所以我猜测。
会不会是你没有绑定web端口,用的是webworker?
来自文档
Web dynos
A web dyno must bind to its assigned $PORT within 60 seconds of startup. If it doesn’t, it is terminated by the dyno manager and a R10 Boot Timeout error is logged. Processes can bind to other ports before and after binding to $PORT.
我正在尝试 运行 一个 Java Discord 机器人,我已将其编译到 Heroku 上的可执行 jar 中。当 运行 在我的机器上安装这个 jar 时,它会连续 运行s 而不会崩溃。 根据 the Heroku instructions for deploying an executable jar via CLI,我 运行 命令行命令:
heroku plugins:install java
heroku create storytelling-bot --no-remote --region eu
heroku deploy:jar StoryTellerBot.jar --app storytelling-bot
这些命令中的最后一个似乎引发了几个 Java 异常,但据我所知这些与我的 .jar 无关,看起来它们是临时文件的清理过程在我的机器上创建的进程出于任何原因无法访问:
remote: https://storytelling-bot.herokuapp.com/ deployed to Heroku
remote:
-----> Done
Exception in thread "Thread-0" java.lang.RuntimeException: Failed to delete C:\Users\Ben\AppData\Local\Temp\heroku-deploy3868081789627054304
at com.heroku.sdk.deploy.DeleteDirectoryRunnable.run(DeleteDirectoryRunnable.java:46)
at java.lang.Thread.run(Unknown Source)
Caused by: java.nio.file.FileSystemException: C:\Users\Ben\AppData\Local\Temp\heroku-deploy3868081789627054304\heroku\app\.heroku-deploy: The process cannot access the file because it is being used by another process.
at sun.nio.fs.WindowsException.translateToIOException(Unknown Source)
at sun.nio.fs.WindowsException.rethrowAsIOException(Unknown Source)
at sun.nio.fs.WindowsException.rethrowAsIOException(Unknown Source)
at sun.nio.fs.WindowsFileSystemProvider.implDelete(Unknown Source)
at sun.nio.fs.AbstractFileSystemProvider.delete(Unknown Source)
at java.nio.file.Files.delete(Unknown Source)
at com.heroku.sdk.deploy.DeleteDirectoryRunnable.visitFile(DeleteDirectoryRunnable.java:21)
at com.heroku.sdk.deploy.DeleteDirectoryRunnable.visitFile(DeleteDirectoryRunnable.java:16)
at java.nio.file.Files.walkFileTree(Unknown Source)
at java.nio.file.Files.walkFileTree(Unknown Source)
at com.heroku.sdk.deploy.DeleteDirectoryRunnable.run(DeleteDirectoryRunnable.java:44)
... 1 more
尽管存在异常,但 jar 运行 在 Heroku 上的运行时间略长于一分钟。分钟结束后,应用停止 运行ning。完整的 Heroku 日志,来自 运行ning
heroku logs --tail -a storytelling-bot
说:
2020-05-09T22:16:05.389817+00:00 app[api]: Initial release by user {my email}
2020-05-09T22:16:05.389817+00:00 app[api]: Release v1 created by user {my email}
2020-05-09T22:16:05.695884+00:00 app[api]: Enable Logplex by user {my email}
2020-05-09T22:16:05.695884+00:00 app[api]: Release v2 created by user {my email}
2020-05-09T22:21:29.000000+00:00 app[api]: Build started by user {my email}
2020-05-09T22:21:41.843885+00:00 app[api]: Scaled to web@1:Free by user {my email}
2020-05-09T22:21:41.824208+00:00 app[api]: Deploy by user {my email}
2020-05-09T22:21:41.824208+00:00 app[api]: Release v3 created by user {my email}
2020-05-09T22:21:42.000000+00:00 app[api]: Build succeeded
2020-05-09T22:21:47.570594+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will override them.
2020-05-09T22:21:47.574241+00:00 app[web.1]: Picked up JAVA_TOOL_OPTIONS: -Xmx300m -Xss512k -XX:CICompilerCount=2 -Dfile.encoding=UTF-8
2020-05-09T22:21:47.802707+00:00 app[web.1]: SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
2020-05-09T22:21:47.802709+00:00 app[web.1]: SLF4J: Defaulting to no-operation (NOP) logger implementation
2020-05-09T22:21:47.802709+00:00 app[web.1]: SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
2020-05-09T22:21:48.770049+00:00 app[web.1]: SLF4J: Failed to load class "org.slf4j.impl.StaticMDCBinder".
2020-05-09T22:21:48.770213+00:00 app[web.1]: SLF4J: Defaulting to no-operation MDCAdapter implementation.
2020-05-09T22:21:48.770431+00:00 app[web.1]: SLF4J: See http://www.slf4j.org/codes.html#no_static_mdc_binder for further details.
2020-05-09T22:21:48.934598+00:00 app[web.1]: [main] INFO JDA - Login Successful!
2020-05-09T22:21:49.283574+00:00 app[web.1]: [JDA MainWS-ReadThread] INFO WebSocketClient - Connected to WebSocket
2020-05-09T22:21:49.547755+00:00 app[web.1]: [JDA MainWS-ReadThread] INFO JDA - Finished Loading!
2020-05-09T22:23:16.058897+00:00 heroku[web.1]: State changed from starting to crashed
2020-05-09T22:23:16.132636+00:00 heroku[web.1]: State changed from crashed to starting
2020-05-09T22:23:20.713652+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will override them.
2020-05-09T22:23:20.717823+00:00 app[web.1]: Picked up JAVA_TOOL_OPTIONS: -Xmx300m -Xss512k -XX:CICompilerCount=2 -Dfile.encoding=UTF-8
2020-05-09T22:23:20.997244+00:00 app[web.1]: SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
2020-05-09T22:23:20.997305+00:00 app[web.1]: SLF4J: Defaulting to no-operation (NOP) logger implementation
2020-05-09T22:23:20.997385+00:00 app[web.1]: SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
2020-05-09T22:23:21.975791+00:00 app[web.1]: SLF4J: Failed to load class "org.slf4j.impl.StaticMDCBinder".
2020-05-09T22:23:21.975824+00:00 app[web.1]: SLF4J: Defaulting to no-operation MDCAdapter implementation.
2020-05-09T22:23:21.975921+00:00 app[web.1]: SLF4J: See http://www.slf4j.org/codes.html#no_static_mdc_binder for further details.
2020-05-09T22:23:22.118150+00:00 app[web.1]: [main] INFO JDA - Login Successful!
2020-05-09T22:23:22.462633+00:00 app[web.1]: [JDA MainWS-ReadThread] INFO WebSocketClient - Connected to WebSocket
2020-05-09T22:23:22.720617+00:00 app[web.1]: [JDA MainWS-ReadThread] INFO JDA - Finished Loading!
2020-05-09T22:24:49.394239+00:00 heroku[web.1]: State changed from starting to crashed
如日志所述,应用程序停止 运行ning。 (请注意,"failed to load class" 行与我在计算机上 运行 运行应用程序时得到的一致;它们不会导致应用程序终止。)
为什么 Jar 会这样崩溃?大概我的 Jar 或我的 Heroku 应用程序需要一些额外的设置才能正常工作——尽管这没有作为 Heroku 通过 CLI 设置可执行 Jar 的指南的一部分提及。
你没有提供太多信息你在你的应用程序中实际做了什么,所以我猜测。
会不会是你没有绑定web端口,用的是webworker?
来自文档
Web dynos A web dyno must bind to its assigned $PORT within 60 seconds of startup. If it doesn’t, it is terminated by the dyno manager and a R10 Boot Timeout error is logged. Processes can bind to other ports before and after binding to $PORT.