如何在ScalaJS项目中解析log4javascript JS库

时间:2016-01-13 10:48:33

标签: scala scala.js log4javascript

我有ScalaJS多项目,我尝试在org.webjars中包含和使用log4javascript。

build.sbt的客户端部分在这里:

lazy val mwlclient = (project in file("client")).
  settings(commonSettings: _*).
  settings(
    persistLauncher := true,
    persistLauncher in Test := false,
    sourceMapsDirectories += mwlsharedJs.base / "..",
    unmanagedSourceDirectories in Compile := Seq((scalaSource in Compile).value),
    libraryDependencies ++= Seq(
      "com.lihaoyi" %%% "scalatags" % "0.5.2" withJavadoc(),
      "be.doeraene" %%% "scalajs-jquery" % "0.8.0" withJavadoc(),
      "com.lihaoyi" %%% "upickle" % "0.3.6" withJavadoc(),
      "com.lihaoyi" %%% "autowire" % "0.2.5" withJavadoc(),
      "org.scala-js" %%% "scalajs-dom" % "0.8.1" withJavadoc(),
      // Javascript libs
      "org.webjars" % "jquery" % "1.10.2",
      "org.webjars" % "jquery-ui" % "1.11.4",
      "org.webjars" % "log4javascript" % "1.4.13",
      "com.lihaoyi" %%% "utest" % "0.3.0" % "test"          
    ),
    jsDependencies += RuntimeDOM,                   
    jsDependencies += ProvidedJS / "urianchor-1.3.3/jquery.uriAnchor.js",
    jsDependencies += "org.webjars" % "jquery" % "1.10.2" / "jquery.js",
    jsDependencies += "org.webjars" % "jquery-ui" % "1.11.4" / "jquery-ui.js",
    jsDependencies += "org.webjars" % "log4javascript" % "1.4.13" / "log4javascript.js",
    testFrameworks += new TestFramework("utest.runner.Framework"),  
    scalaJSStage in Global := FastOptStage,             
    skip in packageJSDependencies := false              
  ).enablePlugins(ScalaJSPlugin, ScalaJSPlay).
  dependsOn(mwlsharedJs)

当我运行sbt包时,我收到以下错误消息:

    [trace] Stack trace suppressed: run last mwlclient/compile:scalaJSPreLinkClasspath for the full output.
    [error] (mwlclient/compile:scalaJSPreLinkClasspath) org.scalajs.core.tools.classpath.JSLibResolveException: Some references to JS libraries could not be resolved:
    [error] - Ambiguous reference to a JS library: log4javascript.js
    [error]   Possible paths found on the classpath:
    [error]   - META-INF/resources/webjars/log4javascript/1.4.13/js/stubs/log4javascript.js
    [error]   - META-INF/resources/webjars/log4javascript/1.4.13/js/log4javascript.js
    [error]   - META-INF/resources/webjars/log4javascript/1.4.13/js/tests/log4javascript.js
    [error]   - META-INF/resources/webjars/log4javascript/1.4.13/log4javascript.js
    [error]   originating from: mwlclient:compile
    [error] Total time: 17 s, completed Jan 13, 2016 11:02:30 AM
    [mwlserver] $ 
    ^M[mwlserver] $ 
    [mwlserver] $ last mwlclient/compile:scalaJSPreLinkClasspath
    org.scalajs.core.tools.classpath.JSLibResolveException: Some references to JS libraries could not be resolved:
    - Ambiguous reference to a JS library: log4javascript.js
      Possible paths found on the classpath:
      - META-INF/resources/webjars/log4javascript/1.4.13/js/stubs/log4javascript.js
      - META-INF/resources/webjars/log4javascript/1.4.13/js/log4javascript.js
      - META-INF/resources/webjars/log4javascript/1.4.13/js/tests/log4javascript.js
      - META-INF/resources/webjars/log4javascript/1.4.13/log4javascript.js
      originating from: mwlclient:compile

        at org.scalajs.core.tools.classpath.PartialClasspath.resolveAllResourceNames(PartialClasspath.scala:137)
        at org.scalajs.core.tools.classpath.PartialClasspath.resolveDependencies(PartialClasspath.scala:80)
        at org.scalajs.core.tools.classpath.PartialClasspath.resolve(PartialClasspath.scala:64)
        at org.scalajs.sbtplugin.ScalaJSPluginInternal$$anonfun$16.apply(ScalaJSPluginInternal.scala:220)
        at org.scalajs.sbtplugin.ScalaJSPluginInternal$$anonfun$16.apply(ScalaJSPluginInternal.scala:217)
        at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
        at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:42)
        at sbt.std.Transform$$anon$4.work(System.scala:64)
        at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:237)
        at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:237)
        at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:18)
        at sbt.Execute.work(Execute.scala:244)
        at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:237)
        at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:237)
        at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:160)
        at sbt.CompletionService$$anon$2.call(CompletionService.scala:30)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)
    [error] (mwlclient/compile:scalaJSPreLinkClasspath) org.scalajs.core.tools.classpath.JSLibResolveException: Some references to JS libraries could not be resolved:
    [error] - Ambiguous reference to a JS library: log4javascript.js
    [error]   Possible paths found on the classpath:
    [error]   - META-INF/resources/webjars/log4javascript/1.4.13/js/stubs/log4javascript.js
    [error]   - META-INF/resources/webjars/log4javascript/1.4.13/js/log4javascript.js
    [error]   - META-INF/resources/webjars/log4javascript/1.4.13/js/tests/log4javascript.js
    [error]   - META-INF/resources/webjars/log4javascript/1.4.13/log4javascript.js
    [error]   originating from: mwlclient:compile

Webjars说log4javascript包含以下文件:

    META-INF/resources/webjars/log4javascript/1.4.13/changelog.txt
    META-INF/resources/webjars/log4javascript/1.4.13/console.html
    META-INF/resources/webjars/log4javascript/1.4.13/console_uncompressed.html
    META-INF/resources/webjars/log4javascript/1.4.13/js/console.html
    META-INF/resources/webjars/log4javascript/1.4.13/js/console_uncompressed.html
    META-INF/resources/webjars/log4javascript/1.4.13/js/liteconsole.html
    META-INF/resources/webjars/log4javascript/1.4.13/js/liteconsole_uncompressed.html
    META-INF/resources/webjars/log4javascript/1.4.13/js/log4javascript.js
    META-INF/resources/webjars/log4javascript/1.4.13/js/log4javascript_lite.js
    META-INF/resources/webjars/log4javascript/1.4.13/js/log4javascript_lite_uncompressed.js
    META-INF/resources/webjars/log4javascript/1.4.13/js/log4javascript_production.js
    META-INF/resources/webjars/log4javascript/1.4.13/js/log4javascript_production_uncompressed.js
    META-INF/resources/webjars/log4javascript/1.4.13/js/log4javascript_uncompressed.js
    META-INF/resources/webjars/log4javascript/1.4.13/js/stubs/log4javascript.js
    META-INF/resources/webjars/log4javascript/1.4.13/js/stubs/log4javascript_lite.js
    META-INF/resources/webjars/log4javascript/1.4.13/js/stubs/log4javascript_lite_uncompressed.js
    META-INF/resources/webjars/log4javascript/1.4.13/js/stubs/log4javascript_production.js
    META-INF/resources/webjars/log4javascript/1.4.13/js/stubs/log4javascript_production_uncompressed.js
    META-INF/resources/webjars/log4javascript/1.4.13/js/stubs/log4javascript_uncompressed.js
    META-INF/resources/webjars/log4javascript/1.4.13/js/tests/log4javascript.js
    META-INF/resources/webjars/log4javascript/1.4.13/js/tests/log4javascript_lite.js
    META-INF/resources/webjars/log4javascript/1.4.13/js/tests/log4javascript_lite_uncompressed.js
    META-INF/resources/webjars/log4javascript/1.4.13/js/tests/log4javascript_production.js
    META-INF/resources/webjars/log4javascript/1.4.13/js/tests/log4javascript_production_uncompressed.js
    META-INF/resources/webjars/log4javascript/1.4.13/js/tests/log4javascript_uncompressed.js
    META-INF/resources/webjars/log4javascript/1.4.13/license.txt
    META-INF/resources/webjars/log4javascript/1.4.13/log4javascript.js
    META-INF/resources/webjars/log4javascript/1.4.13/log4javascript_uncompressed.js
    META-INF/resources/webjars/log4javascript/1.4.13/main.css

如何更改build.sbt以便sbt找到正确的log4javascript.js?

1 个答案:

答案 0 :(得分:0)

使用:

    jsDependencies += "org.webjars" % "log4javascript" % "1.4.13" / "1.4.13/log4javascript.js",

以便log4javascript.js的路径更具体,并且不会选择在类路径中找到的其他3个备选方案。