无法使用 Lift 和 Scala 构建一个简单的项目.js



我做了一个简单的项目:https://github.com/eje211/scalajswithlift

我试图用LiftDSL创建一个JSON对象,并用Scala.js在HTML控制台中打印它

[info] Compiling 1 Scala source to /Users/eeytan/src/scalajs/target/scala-2.11/classes...
[info] Fast optimizing /Users/eeytan/src/scalajs/target/scala-2.11/scala-js-tutorial-fastopt.js
[error] Referring to non-existent class Lnet_liftweb_json_JsonDSL$
[error]   called from Ltutorial_webapp_TutorialApp$.main__V
[error]   called from sjs_js_JSApp$class.$$js$exported$meth$main__sjs_js_JSApp__O
[error]   called from Ltutorial_webapp_TutorialApp$.$$js$exported$meth$main__O
[error]   called from Ltutorial_webapp_TutorialApp$.main
[error]   exported to JavaScript with @JSExport
[error] involving instantiated classes:
[error]   Ltutorial_webapp_TutorialApp$
[error] Referring to non-existent class Lnet_liftweb_json_package$
[error]   called from Ltutorial_webapp_TutorialApp$.main__V
[error]   called from sjs_js_JSApp$class.$$js$exported$meth$main__sjs_js_JSApp__O
[error]   called from Ltutorial_webapp_TutorialApp$.$$js$exported$meth$main__O
[error]   called from Ltutorial_webapp_TutorialApp$.main
[error]   exported to JavaScript with @JSExport
[error] involving instantiated classes:
[error]   Ltutorial_webapp_TutorialApp$
[error] Referring to non-existent class Lnet_liftweb_json_JsonAST$
[error]   called from Ltutorial_webapp_TutorialApp$.main__V
[error]   called from sjs_js_JSApp$class.$$js$exported$meth$main__sjs_js_JSApp__O
[error]   called from Ltutorial_webapp_TutorialApp$.$$js$exported$meth$main__O
[error]   called from Ltutorial_webapp_TutorialApp$.main
[error]   exported to JavaScript with @JSExport
[error] involving instantiated classes:
[error]   Ltutorial_webapp_TutorialApp$
[error] Referring to non-existent method Lnet_liftweb_json_JsonAST$.render__Lnet_liftweb_json_JsonAST$JValue__s_text_Document
[error]   called from Ltutorial_webapp_TutorialApp$.main__V
[error]   called from sjs_js_JSApp$class.$$js$exported$meth$main__sjs_js_JSApp__O
[error]   called from Ltutorial_webapp_TutorialApp$.$$js$exported$meth$main__O
[error]   called from Ltutorial_webapp_TutorialApp$.main
[error]   exported to JavaScript with @JSExport
[error] involving instantiated classes:
[error]   Ltutorial_webapp_TutorialApp$
[error] Referring to non-existent method Lnet_liftweb_json_JsonDSL$.int2jvalue__I__Lnet_liftweb_json_JsonAST$JInt
[error]   called from Ltutorial_webapp_TutorialApp$.main__V
[error]   called from sjs_js_JSApp$class.$$js$exported$meth$main__sjs_js_JSApp__O
[error]   called from Ltutorial_webapp_TutorialApp$.$$js$exported$meth$main__O
[error]   called from Ltutorial_webapp_TutorialApp$.main
[error]   exported to JavaScript with @JSExport
[error] involving instantiated classes:
[error]   Ltutorial_webapp_TutorialApp$
[error] Referring to non-existent method Lnet_liftweb_json_JsonDSL$.pair2Assoc__T2__F1__Lnet_liftweb_json_JsonDSL$JsonAssoc
[error]   called from Ltutorial_webapp_TutorialApp$.main__V
[error]   called from sjs_js_JSApp$class.$$js$exported$meth$main__sjs_js_JSApp__O
[error]   called from Ltutorial_webapp_TutorialApp$.$$js$exported$meth$main__O
[error]   called from Ltutorial_webapp_TutorialApp$.main
[error]   exported to JavaScript with @JSExport
[error] involving instantiated classes:
[error]   Ltutorial_webapp_TutorialApp$
[error] Referring to non-existent method Lnet_liftweb_json_JsonDSL$.string2jvalue__T__Lnet_liftweb_json_JsonAST$JString
[error]   called from Ltutorial_webapp_TutorialApp$.main__V
[error]   called from sjs_js_JSApp$class.$$js$exported$meth$main__sjs_js_JSApp__O
[error]   called from Ltutorial_webapp_TutorialApp$.$$js$exported$meth$main__O
[error]   called from Ltutorial_webapp_TutorialApp$.main
[error]   exported to JavaScript with @JSExport
[error] involving instantiated classes:
[error]   Ltutorial_webapp_TutorialApp$
[error] Referring to non-existent method Lnet_liftweb_json_package$.pretty__s_text_Document__T
[error]   called from Ltutorial_webapp_TutorialApp$.main__V
[error]   called from sjs_js_JSApp$class.$$js$exported$meth$main__sjs_js_JSApp__O
[error]   called from Ltutorial_webapp_TutorialApp$.$$js$exported$meth$main__O
[error]   called from Ltutorial_webapp_TutorialApp$.main
[error]   exported to JavaScript with @JSExport
[error] involving instantiated classes:
[error]   Ltutorial_webapp_TutorialApp$
[trace] Stack trace suppressed: run last compile:fastOptJS for the full output.
[error] (compile:fastOptJS) There were linking errors
[error] Total time: 1 s, completed Oct 30, 2015 5:21:03 PM

我不明白为什么。

如果我从build.sbt中删除注释,我会得到这个错误:

> ~fastOptJS
[trace] Stack trace suppressed: run last compile:scalaJSPreLinkClasspath for the full output.
[error] (compile:scalaJSPreLinkClasspath) org.scalajs.core.tools.classpath.JSLibResolveException: Some references to JS libraries could not be resolved:
[error] - Ambiguous reference to a JS library: jquery.js
[error]   Possible paths found on the classpath:
[error]   - scala/tools/nsc/doc/html/resource/lib/jquery.js
[error]   - META-INF/resources/webjars/jquery/2.1.3/jquery.js
[error]   originating from: scalajs:compile
[error] Total time: 1 s, completed Oct 30, 2015 5:35:09 PM

我不明白发生了什么。我不能在Scala.js中使用Lift JSON DSL吗?

Lift和Lift JSON都是仅JVM的项目。据我所知,它们还没有针对Scala.js进行移植/构建。所以不,你不能在Scala.js.中使用它们

通常,库需要交叉编译,并为Scala/JVM和Scala.js发布,才能使用它们。如果有意义的话,您可以要求Lift开发人员交叉编译(一些)他们的库。

也就是说,在Scala.js中,您通常可以使用JSAPI来处理JSON数据结构:

import scala.scalajs.js
import js.Dynamic.{literal => lit}
val j = lit(a = 2, b = "Hello.")
println(js.JSON.stringify(j, space = 2))

此外,通常情况下,您甚至根本不会直接操作JSON。相反,您可以使用Scala.js可用的任何序列化库,如uPickle、Prickle或BooPickle。

相关内容

  • 没有找到相关文章

最新更新