After deploying to Heroku, Spark server crashes with this exception. My Procfile looks like this:
web: java $JAVA_OPTS -Dserver=$PORT -jar target/myappname-0.0.1-SNAPSHOT.jar
From what I understand, Heroku assigns a new PORT every time the app is deployed. However, I am getting the PORT value from the environment variable set by Heroku, so why can't I get this requested address?
Edit: These are my error logs after correcting the Procfile to -Dserver.port=$PORT.
2015-11-21T16:45:02.832568+00:00 app[web.1]: Picked up JAVA_TOOL_OPTIONS: -Xmx384m -Xss512k -Dfile.encoding=UTF-8
2015-11-21T16:45:04.061714+00:00 app[web.1]: [Thread-1] ERROR spark.webserver.JettySparkServer - ignite failed
2015-11-21T16:45:03.918669+00:00 app[web.1]: [Thread-1] INFO org.eclipse.jetty.util.log - Logging initialized @1084ms
2015-11-21T16:45:03.989340+00:00 app[web.1]: [Thread-1] INFO spark.webserver.JettySparkServer - == Spark has ignited ...
2015-11-21T16:45:03.989452+00:00 app[web.1]: [Thread-1] INFO spark.webserver.JettySparkServer - >> Listening on myappname.herokuapp.com:27925
2015-11-21T16:45:03.998409+00:00 app[web.1]: [Thread-1] INFO org.eclipse.jetty.server.Server - jetty-9.3.z-SNAPSHOT
2015-11-21T16:45:04.062462+00:00 app[web.1]: java.net.BindException: Cannot assign requested address
2015-11-21T16:45:04.062702+00:00 app[web.1]: at sun.nio.ch.Net.bind0(Native Method)
2015-11-21T16:45:04.065229+00:00 app[web.1]: at sun.nio.ch.Net.bind(Net.java:433)
2015-11-21T16:45:04.065305+00:00 app[web.1]: at sun.nio.ch.Net.bind(Net.java:425)
2015-11-21T16:45:04.065472+00:00 app[web.1]: at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
2015-11-21T16:45:04.065412+00:00 app[web.1]: at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223)
2015-11-21T16:45:04.065575+00:00 app[web.1]: at org.eclipse.jetty.server.ServerConnector.open(ServerConnector.java:326)
2015-11-21T16:45:04.065628+00:00 app[web.1]: at org.eclipse.jetty.server.AbstractNetworkConnector.doStart(AbstractNetworkConnector.java:80)
2015-11-21T16:45:04.065688+00:00 app[web.1]: at org.eclipse.jetty.server.ServerConnector.doStart(ServerConnector.java:244)
2015-11-21T16:45:04.065758+00:00 app[web.1]: at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
2015-11-21T16:45:04.067368+00:00 app[web.1]: at org.eclipse.jetty.server.Server.doStart(Server.java:384)
2015-11-21T16:45:04.067370+00:00 app[web.1]: at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
2015-11-21T16:45:04.067370+00:00 app[web.1]: at spark.webserver.JettySparkServer.ignite(JettySparkServer.java:131)
2015-11-21T16:45:04.067371+00:00 app[web.1]: at spark.SparkInstance.lambda$init$0(SparkInstance.java:341)
2015-11-21T16:45:04.067372+00:00 app[web.1]: at java.lang.Thread.run(Thread.java:745)
2015-11-21T16:45:05.052415+00:00 heroku[web.1]: State changed from starting to crashed
2015-11-21T16:45:05.036728+00:00 heroku[web.1]: Process exited with status 100
This happened after adding --port $PORT. Basically, I see no change in the error.
2015-11-21T17:51:14.666062+00:00 app[web.1]: [Thread-0] INFO org.eclipse.jetty.util.log - Logging initialized @230ms
2015-11-21T17:51:14.779260+00:00 app[web.1]: java.net.BindException: Cannot assign requested address
2015-11-21T17:51:14.779449+00:00 app[web.1]: at sun.nio.ch.Net.bind0(Native Method)
2015-11-21T17:51:14.721317+00:00 app[web.1]: [Thread-0] INFO spark.webserver.JettySparkServer - == Spark has ignited ...
2015-11-21T17:51:14.779526+00:00 app[web.1]: at sun.nio.ch.Net.bind(Net.java:433)
2015-11-21T17:51:14.779573+00:00 app[web.1]: at sun.nio.ch.Net.bind(Net.java:425)
2015-11-21T17:51:14.721319+00:00 app[web.1]: [Thread-0] INFO spark.webserver.JettySparkServer - >> Listening on myappname.herokuapp.com:29822
2015-11-21T17:51:14.779601+00:00 app[web.1]: at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223)
2015-11-21T17:51:14.779661+00:00 app[web.1]: at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
2015-11-21T17:51:14.721320+00:00 app[web.1]: [Thread-0] INFO org.eclipse.jetty.server.Server - jetty-9.3.z-SNAPSHOT
2015-11-21T17:51:14.779796+00:00 app[web.1]: at org.eclipse.jetty.server.AbstractNetworkConnector.doStart(AbstractNetworkConnector.java:80)
2015-11-21T17:51:14.779732+00:00 app[web.1]: at org.eclipse.jetty.server.ServerConnector.open(ServerConnector.java:326)
2015-11-21T17:51:14.778639+00:00 app[web.1]: [Thread-0] ERROR spark.webserver.JettySparkServer - ignite failed
2015-11-21T17:51:14.779884+00:00 app[web.1]: at org.eclipse.jetty.server.ServerConnector.doStart(ServerConnector.java:244)
2015-11-21T17:51:14.779949+00:00 app[web.1]: at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
2015-11-21T17:51:14.779980+00:00 app[web.1]: at org.eclipse.jetty.server.Server.doStart(Server.java:384)
2015-11-21T17:51:14.780034+00:00 app[web.1]: at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
2015-11-21T17:51:14.780071+00:00 app[web.1]: at spark.webserver.JettySparkServer.ignite(JettySparkServer.java:131)
2015-11-21T17:51:14.780110+00:00 app[web.1]: at spark.SparkInstance.lambda$init$0(SparkInstance.java:341)
2015-11-21T17:51:14.780153+00:00 app[web.1]: at java.lang.Thread.run(Thread.java:745)
2015-11-21T17:51:15.393560+00:00 heroku[web.1]: Process exited with status 100
2015-11-21T17:51:15.399506+00:00 heroku[web.1]: State changed from starting to crashed
I figured out the problem is that I was setting the domain's IP address in my main method. It seems that we shouldn't be setting this, but only setting the PORT by getting it from the environment variable $PORT.