While running through some tutorial and demo Scalatra apps, I got stuck trying to change the port of a Scalatra service I was running locally (in my case I wanted to run more than two).

The error I got: java.net.BindException: Address already in use

2018-12-31 10:47:10.281:WARN:oeja.AnnotationParser:main: Unrecognized runtime asm version, assuming 393216
2018-12-31 10:47:10.692:INFO:oeja.AnnotationConfiguration:main: Scanning elapsed time=410ms
2018-12-31 10:47:10.833:INFO:oejs.session:main: DefaultSessionIdManager workerName=node0
2018-12-31 10:47:10.833:INFO:oejs.session:main: No SessionScavenger set, using defaults
2018-12-31 10:47:10.835:INFO:oejs.session:main: Scavenging every 600000ms
10:47:10.871 [main] INFO  o.scalatra.servlet.ScalatraListener - The cycle class name from the config: ScalatraBootstrap
10:47:11.020 [main] INFO  o.scalatra.servlet.ScalatraListener - Initializing life cycle class: ScalatraBootstrap
2018-12-31 10:47:11.240:INFO:oejsh.ContextHandler:main: Started o.e.j.w.WebAppContext@1c53fd30{/,file:///****/****/Desktop/scalatra-rest-experiment/target/webapp/,AVAILABLE}{file:///****/****/Desktop/scalatra-rest-experiment/target/webapp/}
java.net.BindException: Address already in use
	at sun.nio.ch.Net.bind0(Native Method)
	at sun.nio.ch.Net.bind(Net.java:433)
	at sun.nio.ch.Net.bind(Net.java:425)
	at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223)
	at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
	at org.eclipse.jetty.server.ServerConnector.openAcceptChannel(ServerConnector.java:334)
	at org.eclipse.jetty.server.ServerConnector.open(ServerConnector.java:302)
	at org.eclipse.jetty.server.AbstractNetworkConnector.doStart(AbstractNetworkConnector.java:80)
	at org.eclipse.jetty.server.ServerConnector.doStart(ServerConnector.java:238)
	at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
	at org.eclipse.jetty.server.Server.doStart(Server.java:397)
	at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
	at org.eclipse.jetty.runner.Runner.run(Runner.java:530)
	at org.eclipse.jetty.runner.Runner.main(Runner.java:571)

Do to some confusion in the docs and changes in Scalatra, I had some trouble understanding what was the correct way to change the port of the style of configuration and project type I was running.

Notes on exactly what I was running, so you can see if it compares with yours:

How to Change the Port

Warning - you need to reload the project (`reload` in SBT worked for me), just running jetty:start and jetty:stop will not be enough to pick up the changes.

Add this to your build.sbt file containerPort in Jetty := 8089

Example logs from the successful startup:

[success] Total time: 0 s, completed Dec 31, 2018 12:30:23 PM
sbt:NaiveScalatraInventoryService> 2018-12-31 12:30:23.518:INFO::main: Logging initialized @119ms to org.eclipse.jetty.util.log.StdErrLog
2018-12-31 12:30:23.525:INFO:oejr.Runner:main: Runner
2018-12-31 12:30:23.659:INFO:oejs.Server:main: jetty-9.4.8.v20171121, build timestamp: 2017-11-21T13:27:37-08:00, git hash: 82b8fb23f757335bb3329d540ce37a2a2615f0a8
2018-12-31 12:30:23.880:WARN:oeja.AnnotationParser:main: Unrecognized runtime asm version, assuming 393216
2018-12-31 12:30:24.319:INFO:oeja.AnnotationConfiguration:main: Scanning elapsed time=439ms
2018-12-31 12:30:24.503:INFO:oejs.session:main: DefaultSessionIdManager workerName=node0
2018-12-31 12:30:24.503:INFO:oejs.session:main: No SessionScavenger set, using defaults
2018-12-31 12:30:24.505:INFO:oejs.session:main: Scavenging every 600000ms
12:30:24.540 [main] INFO  o.scalatra.servlet.ScalatraListener - The cycle class name from the config: ScalatraBootstrap
12:30:24.685 [main] INFO  o.scalatra.servlet.ScalatraListener - Initializing life cycle class: ScalatraBootstrap
2018-12-31 12:30:24.919:INFO:oejsh.ContextHandler:main: Started o.e.j.w.WebAppContext@1c53fd30{/,file:///****/****/Desktop/scalatra-rest-experiment/target/webapp/,AVAILABLE}{file:///****/****/Desktop/scalatra-rest-experiment/target/webapp/}
2018-12-31 12:30:24.938:INFO:oejs.AbstractConnector:main: Started ServerConnector@1ebea008{HTTP/1.1,[http/1.1]}{0.0.0.0:8089}
2018-12-31 12:30:24.938:INFO:oejs.Server:main: Started @1544ms