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

时间:2015-10-30 08:39:17

标签: scala.js

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

我尝试使用Lift DSL创建一个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吗?

1 个答案:

答案 0 :(得分:2)

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

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

也就是说,在Scala.js中,您通常可以使用JS API来处理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可用的任何序列化库,例如uPicklePrickleBooPickle