How to create WAR instead JAR?

Viewed 149

I would like to compile via sbt to WAR instead of JAR file and I followed this guide.

I have changed the build.sbt to:

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"),
// disable .jar publishing
Compile / packageBin / publishArtifact := false,

// create an Artifact for publishing the .war file
Compile / packageWar / artifact := {
  val prev: Artifact = (Compile / packageWar / artifact).value
  prev.withType("war").withExtension("war")
},

// add the .war file to what gets published
addArtifact(Compile / packageWar / artifact, packageWar),
)

and the compile has complained:

/home/developer/scala/user-svc/build.sbt:27: error: not found: value packageWar
Compile / packageWar / artifact := {
^
/home/developer/scala/user-svc/build.sbt:28: error: not found: value packageWar
val prev: Artifact = (Compile / packageWar / artifact).value
^
/home/developer/scala/user-svc/build.sbt:33: error: not found: value packageWar
addArtifact(Compile / packageWar / artifact, packageWar),
^
/home/developer/scala/user-svc/build.sbt:33: error: not found: value packageWar
addArtifact(Compile / packageWar / artifact, packageWar),

What am I doing wrong?

1 Answers

There is a bug in documentation - see https://github.com/sbt/sbt/issues/4490

Try using dedicated sbt plugin - xsbt-web-plugin - instead of reading that website. According to current docs you need to add to project/plugins.sbt

addSbtPlugin("com.earldouglas" % "xsbt-web-plugin" % "4.2.0")

then enable plugin in build.sbt e.g. Jetty

enablePlugins(JettyPlugin)

then you could build WAR with package command.

Related