Reputation: 34099
I have created a web app and when I try to run with sbt run
, it shows:
sbt run
[warn] No sbt.version set in project/build.properties, base directory: /home/developer/scala/user-svc/target/scala-2.13
[info] Loading global plugins from /home/developer/.sbt/1.0/plugins
[info] Set current project to scala-2-13 (in build file:/home/developer/scala/user-svc/target/scala-2.13/)
[error] java.lang.RuntimeException: No main class detected.
[error] at scala.sys.package$.error(package.scala:30)
[error] stack trace is suppressed; run last Compile / bgRun for the full output
[error] (Compile / bgRun) No main class detected.
[error] Total time: 0 s, completed May 23, 2020, 11:44:32 PM
The content of build.sbt
is:
val Http4sVersion = "0.21.4"
val CirceVersion = "0.13.0"
val Specs2Version = "4.9.3"
val LogbackVersion = "1.2.3"
lazy val root = (project in file("."))
.settings(
organization := "io.example",
name := "user-svc",
version := "0.0.1-SNAPSHOT",
scalaVersion := "2.13.2",
libraryDependencies ++= Seq(
"org.http4s" %% "http4s-jetty" % Http4sVersion,
"org.http4s" %% "http4s-jetty-client" % Http4sVersion,
"org.http4s" %% "http4s-circe" % Http4sVersion,
"org.http4s" %% "http4s-dsl" % Http4sVersion,
"io.circe" %% "circe-generic" % CirceVersion,
"org.specs2" %% "specs2-core" % Specs2Version % "test",
"ch.qos.logback" % "logback-classic" % LogbackVersion
),
addCompilerPlugin("org.typelevel" %% "kind-projector" % "0.10.3"),
addCompilerPlugin("com.olegpy" %% "better-monadic-for" % "0.3.1"),
)
scalacOptions ++= Seq(
"-deprecation",
"-encoding", "UTF-8",
"-language:higherKinds",
"-language:postfixOps",
"-feature",
"-Xfatal-warnings",
)
The folder structure should be correct:
What am I doing wrong?
Upvotes: 0
Views: 2670
Reputation: 27595
You don't have a main class, the entrypoint to your program defined. On JVM you have to have at least one class which defines
public static void main(args: String[])
which in Scala's case means something like
object Main {
def main(args: Array[String]): Unit = {
...
}
}
If there is exactly one such class, sbt can detect it, if there are more, you have to tell sbt which one to use using:
mainClass := Some("name.of.my.Main")
in order to call run
. If you run JAR this class can be specified using manifest.mf
or passed explicitly.
Upvotes: 2