vmunier / play-scalajs.g8

Giter8 template to get started with Play and Scala.js.
Apache License 2.0
431 stars 114 forks source link

RuntimeException: Cannot write launcher file, since there is no or multiple mainClasses #47

Closed xyfigo closed 7 years ago

xyfigo commented 7 years ago

I add another scala.js object in the package client/src/main/scala/example named TutorialApp, and the following is the code : object TutorialApp extends JSApp{ def main():Unit = { //println("Hello Wrold!") val parNode = dom.document.createElement("p") val textNode = dom.document.createTextNode("some111") parNode.appendChild(textNode) dom.document.body.appendChild(parNode) } }

where I rerun the index page , it shows the error: And what can I do to add more than one scala.js objects in one Twirl templates?

RuntimeException: Cannot write launcher file, since there is no or multiple mainClasses No source available, here is the exception stack trace: ->java.lang.RuntimeException: Cannot write launcher file, since there is no or multiple mainClasses scala.sys.package$.error(package.scala:27) org.scalajs.sbtplugin.ScalaJSPluginInternal$$anonfun$31$$anonfun$apply$19$$anonfun$apply$22.apply(ScalaJSPluginInternal.scala:450) org.scalajs.sbtplugin.ScalaJSPluginInternal$$anonfun$31$$anonfun$apply$19$$anonfun$apply$22.apply(ScalaJSPluginInternal.scala:450) scala.Option.getOrElse(Option.scala:120) org.scalajs.sbtplugin.ScalaJSPluginInternal$$anonfun$31$$anonfun$apply$19.apply(ScalaJSPluginInternal.scala:449) org.scalajs.sbtplugin.ScalaJSPluginInternal$$anonfun$31$$anonfun$apply$19.apply(ScalaJSPluginInternal.scala:437) scala.Function1$$anonfun$compose$1.apply(Function1.scala:47) sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:40) sbt.std.Transform$$anon$4.work(System.scala:63) sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:228) sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:228) sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:17) sbt.Execute.work(Execute.scala:237) sbt.Execute$$anonfun$submit$1.apply(Execute.scala:228) sbt.Execute$$anonfun$submit$1.apply(Execute.scala:228) sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:159) sbt.CompletionService$$anon$2.call(CompletionService.scala:28) java.util.concurrent.FutureTask.run(FutureTask.java:266) java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) java.util.concurrent.FutureTask.run(FutureTask.java:266) java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) java.lang.Thread.run(Thread.java:745)

vmunier commented 7 years ago

Hello, You get the error Cannot write launcher file, since there is no or multiple mainClasses because you have two objects extending JSApp. You can only have one object extending JSApp per application.

xyfigo commented 7 years ago

Yes, you are right. I am a beginner in ScalaJS, and I find some further information about writing launcher code, ‘How to set mainClass in ScalaJS build.sbt?’ . But I still don't know under the constraints in only one object extending JSApp per application, how can I organize multiple JS files in multiple Twirl templates? And what the mainClass makes sense?