如何在 Scala JS build.sbt 中设置主类?
How to set mainClass in ScalaJS build.sbt?
如何在 ScalaJS 中设置 mainClass build.sbt?
目前我在 build.sbt 中设置主 class 像这样(见最后一行):
enablePlugins(ScalaJSPlugin)
name := "ScalaJS-Exp"
scalaVersion := "2.11.7"
libraryDependencies += "org.scala-js" %%% "scalajs-dom" % "0.8.1"
libraryDependencies += "be.doeraene" %%% "scalajs-jquery" % "0.8.0"
jsDependencies += RuntimeDOM
skip in packageJSDependencies := false
//scalaJSStage in Global := FastOptStage
// uTest settings
libraryDependencies ++= Seq(
"com.lihaoyi" %%% "utest" % "0.3.1" % "test",
"com.lihaoyi" %%% "scalatags" % "0.5.4",
// Javascript libs
"org.webjars" % "jquery" % "1.10.2",
"org.webjars" % "jquery-ui" % "1.11.4"
)
jsDependencies ++= Seq(
"org.webjars" % "jquery" % "1.10.2" / "jquery.js",
"org.webjars" % "jquery-ui" % "1.11.4" / "jquery-ui.js" dependsOn "jquery.js"
)
testFrameworks += new TestFramework("utest.runner.Framework")
persistLauncher in Compile := true
persistLauncher in Test := false
mainClass := Some("htmlExp.HtmlExpApp")
当我执行 sbt 运行 时,我得到:
[warn] Multiple main classes detected. Run 'show discoveredMainClasses' to see the list
[trace] Stack trace suppressed: run last compile:packageScalaJSLauncher for the full output.
[error] (compile:packageScalaJSLauncher) Cannot write launcher file, since there is no or multiple mainClasses
[error] Total time: 1 s, completed Jan 23, 2016 4:36:02 PM
> show discoveredMainClasses
[info] List(htmlExp.HtmlExpApp, tutorial.webapp.MyApp)
[success] Total time: 0 s, completed Jan 23, 2016 4:36:13 PM
>
如果我从 build.sbt 中删除 mainClass 设置,它没有任何效果。错误消息与 mainClass 设置或不设置都相同。
当我尝试 运行Main htmlExp.HtmlExpApp 时在 sbt 提示符下它工作并且 运行s corrent main class.
我如何在 build.sbt 中设置 mainClass 还是因为 ScalaJSPlugin 不支持此设置?
需要在per-configuration基础上设置mainClass
:
mainClass in Compile := Some("htmlExp.HtmlExpApp")
如果您只写 mainClass := ???
,它会为您的整个项目设置 mainClass
。但是,mainClass
检测是在 per-configuration 基础上进行的。因此,自动检测会覆盖您的手动设置。正确覆盖自动检测的唯一方法是为特定配置设置 mainClass
。
请注意,这根本 Scala.js 没有什么特别之处。这同样适用于普通的 JVM 项目(例如,参见 this post)。
如何在 ScalaJS 中设置 mainClass build.sbt?
目前我在 build.sbt 中设置主 class 像这样(见最后一行):
enablePlugins(ScalaJSPlugin)
name := "ScalaJS-Exp"
scalaVersion := "2.11.7"
libraryDependencies += "org.scala-js" %%% "scalajs-dom" % "0.8.1"
libraryDependencies += "be.doeraene" %%% "scalajs-jquery" % "0.8.0"
jsDependencies += RuntimeDOM
skip in packageJSDependencies := false
//scalaJSStage in Global := FastOptStage
// uTest settings
libraryDependencies ++= Seq(
"com.lihaoyi" %%% "utest" % "0.3.1" % "test",
"com.lihaoyi" %%% "scalatags" % "0.5.4",
// Javascript libs
"org.webjars" % "jquery" % "1.10.2",
"org.webjars" % "jquery-ui" % "1.11.4"
)
jsDependencies ++= Seq(
"org.webjars" % "jquery" % "1.10.2" / "jquery.js",
"org.webjars" % "jquery-ui" % "1.11.4" / "jquery-ui.js" dependsOn "jquery.js"
)
testFrameworks += new TestFramework("utest.runner.Framework")
persistLauncher in Compile := true
persistLauncher in Test := false
mainClass := Some("htmlExp.HtmlExpApp")
当我执行 sbt 运行 时,我得到:
[warn] Multiple main classes detected. Run 'show discoveredMainClasses' to see the list
[trace] Stack trace suppressed: run last compile:packageScalaJSLauncher for the full output.
[error] (compile:packageScalaJSLauncher) Cannot write launcher file, since there is no or multiple mainClasses
[error] Total time: 1 s, completed Jan 23, 2016 4:36:02 PM
> show discoveredMainClasses
[info] List(htmlExp.HtmlExpApp, tutorial.webapp.MyApp)
[success] Total time: 0 s, completed Jan 23, 2016 4:36:13 PM
>
如果我从 build.sbt 中删除 mainClass 设置,它没有任何效果。错误消息与 mainClass 设置或不设置都相同。
当我尝试 运行Main htmlExp.HtmlExpApp 时在 sbt 提示符下它工作并且 运行s corrent main class.
我如何在 build.sbt 中设置 mainClass 还是因为 ScalaJSPlugin 不支持此设置?
需要在per-configuration基础上设置mainClass
:
mainClass in Compile := Some("htmlExp.HtmlExpApp")
如果您只写 mainClass := ???
,它会为您的整个项目设置 mainClass
。但是,mainClass
检测是在 per-configuration 基础上进行的。因此,自动检测会覆盖您的手动设置。正确覆盖自动检测的唯一方法是为特定配置设置 mainClass
。
请注意,这根本 Scala.js 没有什么特别之处。这同样适用于普通的 JVM 项目(例如,参见 this post)。