如何创建 WAR 而不是 JAR?
How to create WAR instead JAR?
我想通过 sbt 编译成 WAR 而不是 JAR 文件,我遵循了这个 guide。
我已将 build.sbt
更改为:
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),
)
编译报错:
/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),
我做错了什么?
文档中存在错误 - 请参阅 https://github.com/sbt/sbt/issues/4490
尝试使用专用的 sbt 插件 - xsbt-web-plugin - instead of reading that website. According to current docs 你需要添加到 project/plugins.sbt
addSbtPlugin("com.earldouglas" % "xsbt-web-plugin" % "4.2.0")
然后在 build.sbt
中启用插件,例如码头
enablePlugins(JettyPlugin)
然后您可以使用 package
命令构建 WAR。
我想通过 sbt 编译成 WAR 而不是 JAR 文件,我遵循了这个 guide。
我已将 build.sbt
更改为:
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),
)
编译报错:
/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),
我做错了什么?
文档中存在错误 - 请参阅 https://github.com/sbt/sbt/issues/4490
尝试使用专用的 sbt 插件 - xsbt-web-plugin - instead of reading that website. According to current docs 你需要添加到 project/plugins.sbt
addSbtPlugin("com.earldouglas" % "xsbt-web-plugin" % "4.2.0")
然后在 build.sbt
中启用插件,例如码头
enablePlugins(JettyPlugin)
然后您可以使用 package
命令构建 WAR。