Compiling and running WebSocketCoreExample.java

I am getting a runtime error and the I’m sure it’s some dependency problem. Trouble is, I can’t find a suggested list of dependencies if I want to make this example run from Java using Maven. The example code is here: https://github.com/akka/akka-http/blob/v10.1.1/docs/src/test/java/docs/http/javadsl/server/WebSocketCoreExample.java

The specific error is when the code tries to bindAndHandleSync

And the error is:

Exception in thread "main" java.lang.NoClassDefFoundError: akka/util/ConstantFun$
	at akka.http.impl.model.parser.HeaderParser$.Settings$default$3(HeaderParser.scala:199)
	at akka.http.impl.model.parser.HeaderParser$.<init>(HeaderParser.scala:217)
	at akka.http.impl.model.parser.HeaderParser$.<clinit>(HeaderParser.scala)
	at akka.http.scaladsl.model.headers.ProductVersion$.parseMultiple(ProductVersion.scala:31)
	at akka.http.scaladsl.model.headers.User$minusAgent$.apply(headers.scala:952)
	at akka.http.impl.settings.ClientConnectionSettingsImpl$$anonfun$fromSubConfig$1.apply(ClientConnectionSettingsImpl.scala:51)
	at akka.http.impl.settings.ClientConnectionSettingsImpl$$anonfun$fromSubConfig$1.apply(ClientConnectionSettingsImpl.scala:51)
	at scala.Option.map(Option.scala:146)
	at akka.http.impl.settings.ClientConnectionSettingsImpl$.fromSubConfig(ClientConnectionSettingsImpl.scala:51)
	at akka.http.impl.settings.ConnectionPoolSettingsImpl$.fromSubConfig(ConnectionPoolSettingsImpl.scala:61)
	at akka.http.impl.settings.ConnectionPoolSettingsImpl$.fromSubConfig(ConnectionPoolSettingsImpl.scala:52)
	at akka.http.impl.util.SettingsCompanion.apply(SettingsCompanion.scala:51)
	at akka.http.scaladsl.settings.ConnectionPoolSettings$.apply(ConnectionPoolSettings.scala:79)
	at akka.http.scaladsl.settings.ConnectionPoolSettings$.apply(ConnectionPoolSettings.scala:78)
	at akka.http.scaladsl.settings.SettingsCompanion$class.apply(SettingsCompanion.scala:19)
	at akka.http.scaladsl.settings.ConnectionPoolSettings$.apply(ConnectionPoolSettings.scala:78)
	at akka.http.scaladsl.HttpExt.<init>(Http.scala:61)
	at akka.http.scaladsl.Http$.createExtension(Http.scala:956)
	at akka.http.scaladsl.Http$.createExtension(Http.scala:829)
	at akka.actor.ActorSystemImpl.registerExtension(ActorSystem.scala:866)
	at akka.actor.ExtensionId$class.apply(Extension.scala:77)
	at akka.http.scaladsl.Http$.apply(Http.scala:951)
	at akka.http.scaladsl.Http$.apply(Http.scala:829)
	at akka.http.javadsl.Http.delegate$lzycompute(Http.scala:45)
	at akka.http.javadsl.Http.delegate(Http.scala:45)
	at akka.http.javadsl.Http.defaultServerHttpContext(Http.scala:826)
	at akka.http.javadsl.Http.bindAndHandleSync(Http.scala:278)
	at com.xxx.yyy.core.WebSocketCoreExample.main(WebSocketCoreExample.java:66)

That comes from akka-actor which should be pulled in transitively by maven. So unless you have manually added your own dependency on an old version of Akka to the project it should work.

The maven tab in the docs https://doc.akka.io/docs/akka-http/current/introduction.html#using-akka-http should give you all you need to be able to compile and run that sample.

“So unless you…”, was exactly the case. Thank you.