使用带Markdown的Scalate在Scalatra中的java.lang.NoSuchMethodError

时间:2013-08-20 21:15:06

标签: scala pug nosuchmethoderror scalatra scalate

所以我有一个Scalatra应用程序(使用Scalatra 2.2.1)。我正在使用Scalate构建视图;我决定选择Jade / Markdown一两。只有一个问题:如果我尝试在玉石模板中使用markdown(以:markdown标签开头),我会得到这个:

scala.Predef$.any2ArrowAssoc(Ljava/lang/Object;)Lscala/Predef$ArrowAssoc;
java.lang.NoSuchMethodError: scala.Predef$.any2ArrowAssoc(Ljava/lang/Object;)Lscala/Predef$ArrowAssoc;

at org.fusesource.scalamd.Markdown$.<init>(md.scala:119)
at org.fusesource.scalamd.Markdown$.<clinit>(md.scala:-1)
at org.fusesource.scalate.filter.ScalaMarkdownFilter$.filter(ScalaMarkdownFilter.scala:32)
at org.fusesource.scalate.RenderContext$class.filter(RenderContext.scala:276)
at org.fusesource.scalate.DefaultRenderContext.filter(DefaultRenderContext.scala:30)
at org.fusesource.scalate.RenderContext$class.value(RenderContext.scala:235)
at org.fusesource.scalate.DefaultRenderContext.value(DefaultRenderContext.scala:30)
at templates.views.$_scalate_$about_jade$.$_scalate_$render(about_jade.scala:37)
at templates.views.$_scalate_$about_jade.render(about_jade.scala:48)
at org.fusesource.scalate.DefaultRenderContext.capture(DefaultRenderContext.scala:92)
at org.fusesource.scalate.layout.DefaultLayoutStrategy.layout(DefaultLayoutStrategy.scala:45)
at org.fusesource.scalate.TemplateEngine$$anonfun$layout$1$$anonfun$apply$mcV$sp$1.apply$mcV$sp(TemplateEngine.scala:559)
at org.fusesource.scalate.TemplateEngine$$anonfun$layout$1$$anonfun$apply$mcV$sp$1.apply(TemplateEngine.scala:559)
at org.fusesource.scalate.TemplateEngine$$anonfun$layout$1$$anonfun$apply$mcV$sp$1.apply(TemplateEngine.scala:559)

所以这很酷。一旦删除:markdown标志,错误就会消失,除此之外,所有内容都会编译(超出标记时无法正确呈现)。

到目前为止我所知道并找到的事情:

  1. 有人认为这个错误是构建中某处不兼容的Scala版本的副产品。我的build.scala将Scala版本定义为2.10.0,其中Scalatra明确与。
  2. 兼容
  3. ...说,我已经不知道哪个版本的Scalate Scalatra会进入,而我试图覆盖它的尝试到目前为止还没有。我知道当前稳定的Scalate(1.6.1)只与Scala 2.10.0兼容 - 但这就是我正在使用的。
  4. 但是,我确定我的课程路径很干净。我没有冲突的Scala版本。依赖项中的 Everything 为2.10.0。
  5. 以前有人和这个人一起工作过吗?有任何想法吗?

    修改

    根据请求,这是我的构建定义:

    //build.sbt 
    libraryDependencies += "org.scalatest" %% "scalatest" % "2.0.M5b" % "test"                                                                                                                                     
    
    libraryDependencies += "org.twitter4j" % "twitter4j-core" % "3.0.3"                                                                                                                                            
    
    libraryDependencies += "org.fusesource.scalamd" % "scalamd" % "1.5" 
    
    //build.properties
    sbt.version=0.12.3
    
    //build.scala
    import sbt._                                                                                                                                                                                                   
    import Keys._                                                                                                                                                                                                  
    import org.scalatra.sbt._                                                                                                                                                                                      
    import org.scalatra.sbt.PluginKeys._                                                                                                                                                                           
    import com.mojolly.scalate.ScalatePlugin._                                                                                                                                                                     
    import ScalateKeys._                                                                                                                                                                                           
    
    object TheRangeBuild extends Build {                                                                                                                                                                           
      val Organization = "com.gastove"                                                                                                                                                                             
      val Name = "The Range"                                                                                                                                                                                       
      val Version = "0.1.0-SNAPSHOT"                                                                                                                                                                               
      val ScalaVersion = "2.10.0"                                                                                                                                                                                  
      val ScalatraVersion = "2.2.1"                                                                                                                                                                                
    
      lazy val project = Project (                                                                                                                                                                                 
        "the-range",                                                                                                                                                                                               
        file("."),                                                                                                                                                                                                 
        settings = Defaults.defaultSettings ++ ScalatraPlugin.scalatraWithJRebel ++ scalateSettings ++ Seq(                                                                                                        
          organization := Organization,                                                                                                                                                                            
          name := Name,                                                                                                                                                                                            
          version := Version,                                                                                                                                                                                      
          scalaVersion := ScalaVersion,                                                                                                                                                                            
          resolvers += Classpaths.typesafeReleases,                                                                                                                                                                
          libraryDependencies ++= Seq(                                                                                                                                                                             
            "org.scalatra" %% "scalatra" % ScalatraVersion,                                                                                                                                                        
            "org.scalatra" %% "scalatra-scalate" % ScalatraVersion,                                                                                                                                                
            "org.scalatra" %% "scalatra-specs2" % ScalatraVersion % "test",                                                                                                                                        
            "ch.qos.logback" % "logback-classic" % "1.0.6" % "runtime",                                                                                                                                            
            "org.eclipse.jetty" % "jetty-webapp" % "8.1.8.v20121106" % "compile;container",                                                                                                                        
            "org.eclipse.jetty.orbit" % "javax.servlet" % "3.0.0.v201112011016" % "compile;container;provided;test" artifacts (Artifact("javax.servlet", "jar", "jar"))                                            
          ),                                                                                                                                                                                                       
          scalateTemplateConfig in Compile <<= (sourceDirectory in Compile){ base =>                                                                                                                               
            Seq(                                                                                                                                                                                                   
              TemplateConfig(                                                                                                                                                                                      
                base / "webapp" / "WEB-INF" / "templates",                                                                                                                                                         
                Seq.empty,  /* default imports should be added here */                                                                                                                                             
                Seq(                                                                                                                                                                                               
                  Binding("context", "_root_.org.scalatra.scalate.ScalatraRenderContext", importMembers = true, isImplicit = true)                                                                                 
                ),  /* add extra bindings here */                                                                                                                                                                  
                Some("templates")                                                                                                                                                                                  
              )                                                                                                                                                                                                    
            )                                                                                                                                                                                                      
          }                                                                                                                                                                                                        
        ) ++ seq(com.typesafe.startscript.StartScriptPlugin.startScriptForClassesSettings: _*)                                                                                                                     
      )                                                                                                                                                                                                            
    }
    

2 个答案:

答案 0 :(得分:1)

使用markdown filter时,需要将scalamd库添加为运行时依赖项:

"org.fusesource.scalamd" %% "scalamd" % "1.6"

最新版本可在Maven Central

上找到

此外,您可以删除build.sbt文件并将依赖项放入build.scala文件中,这会使事情变得更简单。

import sbt._
import Keys._
import org.scalatra.sbt._
import org.scalatra.sbt.PluginKeys._
import com.mojolly.scalate.ScalatePlugin._
import ScalateKeys._
object TheRangeBuild extends Build {
  val Organization = "com.gastove"
  val Name = "The Range"
  val Version = "0.1.0-SNAPSHOT"
  val ScalaVersion = "2.10.0"
  val ScalatraVersion = "2.2.1"
  lazy val project = Project(
    "the-range",
    file("."),
    settings = Defaults.defaultSettings ++ ScalatraPlugin.scalatraWithJRebel ++ scalateSettings ++ Seq(
      organization := Organization,
      name := Name,
      version := Version,
      scalaVersion := ScalaVersion,
      resolvers += Classpaths.typesafeReleases,
      libraryDependencies ++= Seq(  // adding this Seq to the libraryDependencies
        "org.scalatra" %% "scalatra" % ScalatraVersion,
        "org.scalatra" %% "scalatra-scalate" % ScalatraVersion,
        "org.scalatra" %% "scalatra-specs2" % ScalatraVersion % "test",
        "ch.qos.logback" % "logback-classic" % "1.0.6" % "runtime",
        "org.eclipse.jetty" % "jetty-webapp" % "8.1.8.v20121106" % "compile;container",
        "org.scalatest" %% "scalatest" % "2.0.M5b" % "test",
        "org.twitter4j" % "twitter4j-core" % "3.0.3",
        "org.fusesource.scalamd" % "scalamd" % "1.6",
        "org.eclipse.jetty.orbit" % "javax.servlet" % "3.0.0.v201112011016" % "compile;container;provided;test" artifacts (Artifact("javax.servlet", "jar", "jar"))
      ),
      scalateTemplateConfig in Compile <<= (sourceDirectory in Compile){ base =>
        Seq(
          TemplateConfig(
            base / "webapp" / "WEB-INF" / "templates",
            Seq.empty,  /* default imports should be added here */
            Seq(
              Binding("context", "_root_.org.scalatra.scalate.ScalatraRenderContext", importMembers = true, isImplicit = true)
            ),  /* add extra bindings here */
            Some("templates")
          )
        )
      }
    ) ++ seq(com.typesafe.startscript.StartScriptPlugin.startScriptForClassesSettings: _*)
  )
}

答案 1 :(得分:1)

这来自:

libraryDependencies += "org.fusesource.scalamd" % "scalamd" % "1.5" 

查看scalamd-1.5 pom.xml,它是针对Scala 2.8.1构建的,它与2.10不兼容。

依赖关系解析保持2.10并丢弃2.8.1依赖关系,最终导致此类路径问题。

你唯一的解决方案就是尝试针对Scala 2.10构建一个新的scalamd版本,可能会修复一些东西来实现它,然后发布它(至少在本地)。