How to set up scala for web developing?

Hello, I want to make a website using Scala as backend, but how do I set it up? I mean, PHP is the easiest, it is already set up on all hosts and so on…

1 Like

You need to select a web server. Here is a list of the most popular one:

there are many more …

The de facto build tool is sbt.

It depends a lot on the type of server you want to build. If you want to create a rest/json server here is an example:

1 Like

If you are looking for a full-stack web framework based on Scala, I’d recommend the Play Framework.

1 Like

I’ll go ahead and throw in Lift as a great Web Framework to use.

As for configuring the server, I typically use sbt-assembly to build an uberjar and just deploy that on the server. An uberjar rolls up all the dependencies into a single JAR file, so the only think you need on your server is the correct version of Java. (Lift requires Java 8, fwiw.)

After that, you can just run:

$ java -jar /path/to/your/uberjar.jar

You’ll probably also want to install nginx on your server as a reverse proxy, but you’d need to do that with PHP, too.

Let me know if you have any further questions. Happy to help.

1 Like

What about Scala.js? Can it be compared to the solutions presented above, or is it only a front-end development layer? I looked it up a bit and I find it very attractive for displaying in the browser as a typed alternative to HTML or templating engines (when used with Scalatags). What do you think?

You can run Scala.js on the server, but AFAIK none of the above frameworks are compatible with it. On the other hand, you could use fascades for JavaScript frameworks like Express.

I would definitely consider Lift. It’s an excellent pure-Scala web
framework.

My Lift application is deployed as a WAR file on both Jetty (for
development) and Tomcat (test and production).

I have found that the Lift actors are simpler and lighter weight than Akka.
While not as powerful as Akka, they do very nicely in smaller apps.

Can you define specifically what you mean by “compatible”? I’m a Lift committer so if there’s something we aren’t doing that would be helpful for folks interested in Scala.js I’d like to know.

As far as I’m aware, sbt can be configured to output compiled JavaScript into the target folder that ends up on the classpath for a running application - which would be the extent of the integration we would need. But please correct me if there’s something else we can do.

Sorry, I expressed my point poorly. I meant “compile your server code to JS and run it with Node”, since most of the discussion seemed to be around the server side.

I can’t speak for Lift, but Play/JVM server + Scala.js works pretty great together. I assume the same applies to Lift.

1 Like