由于WebJarAssets资源初始化失败,我在运行应用程序时遇到NoSuchMethodError有点问题。 我希望在我的scala.html文件
中使用如下的WebJarAssets<script type='text/javascript' src='@routes.WebJarAssets.at(WebJarAssets.fullPath("react", "react.js"))'></script>
<script type='text/javascript' src='@routes.WebJarAssets.at(WebJarAssets.fullPath("react", "react-dom.js"))'></script>
<script type='text/javascript' src='@routes.WebJarAssets.at(WebJarAssets.fullPath("jquery", "jquery.js"))'></script>
我的build.sbt如下
name := "myApp"
version := "1.0"
lazy val root = (project in file(".")).enablePlugins(PlayJava, SbtWeb, PlayEbean)
scalaVersion := "2.11.8"
JsEngineKeys.engineType := JsEngineKeys.EngineType.Node
libraryDependencies ++= Seq(
javaJdbc,
cache,
javaWs,
"mysql" % "mysql-connector-java" % "5.1.27",
"commons-io" % "commons-io" % "2.5" withSources(),
"org.webjars" % "webjars-play_2.11" % "2.4.0-2",
//"org.webjars" %% "webjars-play" % "2.5.0",
"org.webjars" % "react" % "15.3.1",
"org.webjars.npm" % "react-dom" % "15.0.1",
"org.apache.poi" % "poi" % "3.14",
"org.apache.poi" % "poi-ooxml" % "3.14",
"org.webjars" % "jquery" % "3.1.0",
"org.apache.pdfbox" % "pdfbox" % "2.0.3",
"org.webjars" % "highcharts" % "4.2.5",
"org.webjars" % "material-design-icons" % "3.0.0",
evolutions,
"javax.mail" % "mail" % "1.4.7",
"be.objectify" %% "deadbolt-java" % "2.5.3"
)
resolvers += Resolver.url("Typesafe Ivy releases", url("https://repo.typesafe.com/typesafe/ivy-releases"))(Resolver.ivyStylePatterns)
fork in run := false
如您所见,我尝试过几个不同的webjar库 我的应用程序的plugin.sbt如下
// The Play plugin
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.5.12")
// Web plugins
addSbtPlugin("com.typesafe.sbt" % "sbt-coffeescript" % "1.0.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-less" % "1.1.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-jshint" % "1.0.4")
addSbtPlugin("com.typesafe.sbt" % "sbt-rjs" % "1.0.8")
addSbtPlugin("com.typesafe.sbt" % "sbt-digest" % "1.1.1")
addSbtPlugin("com.typesafe.sbt" % "sbt-mocha" % "1.1.0")
addSbtPlugin("org.irundaia.sbt" % "sbt-sassify" % "1.4.6")
addSbtPlugin("io.teamscala.sbt" % "sbt-babel" % "1.0.5")
addSbtPlugin("com.typesafe.sbt" % "sbt-gzip" % "1.0.0")
//addSbtPlugin("com.github.stonexx.sbt" % "sbt-babeljs" % "1.0.5")
// Play enhancer - this automatically generates getters/setters for public fields
// and rewrites accessors of these fields to use the getters/setters. Remove this
// plugin if you prefer not to have this feature, or disable on a per project
// basis using disablePlugins(PlayEnhancer) in your build.sbt
addSbtPlugin("com.typesafe.sbt" % "sbt-play-enhancer" % "1.1.0")
// Play Ebean support, to enable, uncomment this line, and enable in your build.sbt using
// enablePlugins(PlayEbean).
addSbtPlugin("com.typesafe.sbt" % "sbt-play-ebean" % "4.0.0-M2")
//sbt plugin for eclipse
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "5.1.0")
运行应用程序后,我得到以下堆栈跟踪
1) Error injecting constructor, java.lang.NoSuchMethodError: controllers.AssetsBuilder.<init>(Lplay/api/http/HttpErrorHandler;)V
at controllers.WebJarAssets.<init>(WebJarAssets.scala:20)
at controllers.WebJarAssets.class(WebJarAssets.scala:20)
while locating controllers.WebJarAssets
for the 10th parameter of router.Routes.<init>(Routes.scala:61)
while locating router.Routes
while locating play.api.inject.RoutesProvider
while locating play.api.routing.Router
for the 1st parameter of play.api.http.JavaCompatibleHttpRequestHandler.<init>(HttpRequestHandler.scala:205)
while locating play.api.http.JavaCompatibleHttpRequestHandler
while locating play.api.http.HttpRequestHandler
for the 6th parameter of play.api.DefaultApplication.<init>(Application.scala:228)
at play.api.DefaultApplication.class(Application.scala:227)
while locating play.api.DefaultApplication
while locating play.api.Application
1 error
at com.google.inject.internal.InjectorImpl$2.get(InjectorImpl.java:1028)
at com.google.inject.internal.InjectorImpl.getInstance(InjectorImpl.java:1054)
at play.api.inject.guice.GuiceInjector.instanceOf(GuiceInjectorBuilder.scala:405)
at play.api.inject.guice.GuiceInjector.instanceOf(GuiceInjectorBuilder.scala:400)
at play.api.inject.guice.GuiceApplicationBuilder.build(GuiceApplicationBuilder.scala:137)
at play.api.inject.guice.GuiceApplicationLoader.load(GuiceApplicationLoader.scala:21)
at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1$$anonfun$1$$anonfun$2.apply(DevServerStart.scala:166)
at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1$$anonfun$1$$anonfun$2.apply(DevServerStart.scala:163)
at play.utils.Threads$.withContextClassLoader(Threads.scala:21)
at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(DevServerStart.scala:163)
Caused by: java.lang.NoSuchMethodError: controllers.AssetsBuilder.<init>(Lplay/api/http/HttpErrorHandler;)V
at controllers.WebJarAssets.<init>(WebJarAssets.scala:20)
at controllers.WebJarAssets$$FastClassByGuice$$db4380e1.newInstance(<generated>)
at com.google.inject.internal.DefaultConstructionProxyFactory$FastClassProxy.newInstance(DefaultConstructionProxyFactory.java:89)
at com.google.inject.internal.ConstructorInjector.provision(ConstructorInjector.java:111)
at com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:90)
at com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:268)
at com.google.inject.internal.ProviderToInternalFactoryAdapter$1.call(ProviderToInternalFactoryAdapter.java:46)
at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1092)
at com.google.inject.internal.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:40)
at com.google.inject.internal.SingletonScope$1.get(SingletonScope.java:194)
任何有关可能导致此问题的见解都会非常有用。
答案 0 :(得分:1)
您正在使用Play 2.5,因此请使用以下依赖项:
"org.webjars" %% "webjars-play" % "2.5.0-4"
并确保您已定义路线:
GET /assets/*file controllers.Assets.at(path="/public", file)