我有一个要在Heroku上托管的Java应用程序。它是主机大约90秒钟,然后停止,因为我相信它没有在监听端口。
2020-07-15T02:11:28.294784+00:00 heroku[web.1]: Starting process with command `java $JAVA_OPTS -Dserver.port=48951 -cp target/classes:target/dependency/* com.marcuzzo.JDABot.Bot`
2020-07-15T02:11:31.004137+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will override them.
2020-07-15T02:11:31.009533+00:00 app[web.1]: Picked up JAVA_TOOL_OPTIONS: -Xmx300m -Xss512k -XX:CICompilerCount=2 -Dfile.encoding=UTF-8
2020-07-15T02:11:34.108569+00:00 app[web.1]: 2373 [main] INFO net.dv8tion.jda.api.JDA - Login Successful!
2020-07-15T02:11:34.412661+00:00 app[web.1]: 2677 [JDA MainWS-WriteThread] INFO net.dv8tion.jda.internal.requests.WebSocketClient - Connected to WebSocket
2020-07-15T02:11:34.805431+00:00 app[web.1]: 3070 [JDA MainWS-ReadThread] INFO net.dv8tion.jda.api.JDA - Finished Loading!
90秒后:
2020-07-15T02:13:01.097991+00:00 heroku[web.1]: Starting process with command `java $JAVA_OPTS -Dserver.port=54606 -cp target/classes:target/dependency/* com.marcuzzo.JDABot.Bot`
2020-07-15T02:13:03.183606+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will override them.
2020-07-15T02:13:03.190294+00:00 app[web.1]: Picked up JAVA_TOOL_OPTIONS: -Xmx300m -Xss512k -XX:CICompilerCount=2 -Dfile.encoding=UTF-8
2020-07-15T02:13:04.648587+00:00 app[web.1]: 1213 [main] INFO net.dv8tion.jda.api.JDA - Login Successful!
2020-07-15T02:13:04.825861+00:00 app[web.1]: 1390 [JDA MainWS-ReadThread] INFO net.dv8tion.jda.internal.requests.WebSocketClient - Connected to WebSocket
2020-07-15T02:13:05.073488+00:00 app[web.1]: 1638 [JDA MainWS-ReadThread] INFO net.dv8tion.jda.api.JDA - Finished Loading!
2020-07-15T02:14:31.614718+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 90 seconds of launch
2020-07-15T02:14:31.636741+00:00 heroku[web.1]: Stopping process with SIGKILL
2020-07-15T02:14:31.725476+00:00 heroku[web.1]: Process exited with status 137
2020-07-15T02:14:31.771994+00:00 heroku[web.1]: State changed from starting to crashed
我正在使用JDA(https://github.com/DV8FromTheWorld/JDA)。我不确定是否可以实现某种方法来监听端口以维持连接,或者是否还有其他方法可以实现。
我的个人档案:java $JAVA_OPTS -Dserver.port=$PORT -cp target/classes:target/dependency/* com.marcuzzo.JDABot.Bot
从查看有关此问题的其他问题来看,我已将-Dserver.port=$PORT
添加到我的procfile中并将其保存在我的应用程序中:
int port = Integer.parseInt(System.getenv("PORT"));
String host = "0.0.0.0";
这只是少数几行应用程序,因为我想首先脱离托管。
我看到一个post说我需要添加listen()
才能侦听该端口,但是我不相信我能够使用该方法。那可能只是用另一种语言,或者可能在我不知道的图书馆中。我尝试过JDA.AddEventListener
监听端口,但我确实认为这是正确的,因为它似乎不起作用。