No main class detected on Scala Play app

I’m trying a Hello World Scala app using Play from the book, Scala Reactive Programming. When I try to run the app, it gives me “java.lang.RuntimeException: No main class detected.”. I’ve spent a ton of time on Google but haven’t found a working solution.

Solution 1:
This statement in build.sbt “lazy val usuallyCalledRoot = project.in(file(”."))". I still get the same error.

Solution 2:
This command, “sbt server/run”. That doesn’t even seem to be valid command. “sbt run” gives me the original error, and “sbt server” isn’t a valid command.

Can anyone please throw me a bone?
TIA

Could you post the full code set from the example. The scala files, build.sbt, etc.

Sounds like the Play plugin is not loaded. How did you install it? Did you download the Play app as a package? Or did you add it to your SBT project files?

HelloWorldNoDIController:
package controllers

import play.api.mvc.{Action, ControllerComponents}

class HelloWorldNoDIController extends Controller {
  def helloWorld = Action {
Ok(views.html.helloWorld("Hello World Without DI."))
  }
}

HelloWorld.scala.html:
helloWorld.scala.html
@(message: String)
@message

routes:
# Routes
# This file defines all application routes (Higher priority routes first)
# ~~~~# HelloWorldController without using Play DI
GET /helloWorld controllers.HelloWorldNoDIController.helloWorld
# Map static resources from the /public folder to the /assets URL path
GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset)

build.sbt:
name := “play-scala-helloworld-app”

version := "0.1"

scalaVersion := "2.12.4"

// https://mvnrepository.com/artifact/com.typesafe.play/play
libraryDependencies += "com.typesafe.play" %% "play" % "2.6.13"
1 Like

Right, so I think the easiest way to get everything you need to get going with that code is, after installing sbt, is to run the following at the command line:
sbt new playframework/play-scala-seed.g8

You will get a whole starter framework for your Play application. That is, from what you posted, you are still missing several items, including the directory structure, all of which are important to actually seeing your app show up running on http://localhost:9000 when you run it.

Once you see the basic app working, you can find the right places to paste the code you pasted from that example.

1 Like

The problem is that Play is not just a library, but also an SBT plugin.

In file project/plugins.sbt (create if not existent), add the following line:

addSbtPlugin(“com.typesafe.play” % “sbt-plugin” % “2.6.13”)

I wish Play would emphasize more on simple setup instructions.

I’m afraid that didn’t help. :frowning:

That worked! It scaffold’d me an app that starts. I can work with that. Thank you

:+1: