Play framework 2.4: NoClassDefFoundError: play/api/cache/CachePlugin

♀尐吖头ヾ 提交于 2019-12-07 06:09:33

问题


In trying to update from Play 2.2 to Play 2.4, I've hit this stumbling block.

I've got the memcached2 plugin also added but disabled.

my conf file:

# Cache configuration
# ~~~~~
# To avoid conflict with play2-memcached's Memcached-based cache module
play.modules.disabled+="com.github.mumoshu.play2.memcached.MemcachedModule"
play.modules.enabled+="play.api.cache.EhCacheModule"

# Well-known configuration provided by Play
play.modules.cache.defaultCache=default
play.modules.cache.bindCaches=["db-cache", "user-cache", "session-cache"]

Taken from the example on the github page: https://github.com/mumoshu/play2-memcached

The relevant part in my build.sbt:

lazy val buildSettings = Seq(
  scalaVersion := "2.10.5"
)

lazy val root = (project in file(".")).enablePlugins(PlayJava, PlayEbean, SbtTwirl)
  .settings(buildSettings: _*)

libraryDependencies ++= Seq(
  javaJdbc,
  cache,
  javaWs,

  "net.spy" % "spymemcached" % "2.12.0",
  "com.github.mumoshu" %% "play2-memcached-play24" % "0.7.0"
)

I'm getting the following stacktrace:

play.api.UnexpectedException: Unexpected exception[NoClassDefFoundError: play/api/cache/CachePlugin]
    at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(DevServerStart.scala:169) ~[play-server_2.10-2.4.2.jar:2.4.2]
    at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(DevServerStart.scala:121) ~[play-server_2.10-2.4.2.jar:2.4.2]
    at scala.Option.map(Option.scala:145) ~[scala-library-2.10.5.jar:na]
    at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1.apply(DevServerStart.scala:121) ~[play-server_2.10-2.4.2.jar:2.4.2]
    at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1.apply(DevServerStart.scala:119) ~[play-server_2.10-2.4.2.jar:2.4.2]
    at scala.util.Success.flatMap(Try.scala:200) ~[scala-library-2.10.5.jar:na]
    at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1.apply(DevServerStart.scala:119) ~[play-server_2.10-2.4.2.jar:2.4.2]
    at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1.apply(DevServerStart.scala:111) ~[play-server_2.10-2.4.2.jar:2.4.2]
    at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1$1(Future.scala:24) ~[scala-library-2.10.5.jar:na]
    at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24) ~[scala-library-2.10.5.jar:na]
    at java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1402) ~[na:1.8.0_60]
    at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289) ~[na:1.8.0_60]
    at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056) ~[na:1.8.0_60]
    at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692) ~[na:1.8.0_60]
    at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157) ~[na:1.8.0_60]
Caused by: java.lang.NoClassDefFoundError: play/api/cache/CachePlugin
    at java.lang.ClassLoader.defineClass1(Native Method) ~[na:1.8.0_60]
    at java.lang.ClassLoader.defineClass(ClassLoader.java:760) ~[na:1.8.0_60]
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) ~[na:1.8.0_60]
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:467) ~[na:1.8.0_60]
    at java.net.URLClassLoader.access$100(URLClassLoader.java:73) ~[na:1.8.0_60]
    at java.net.URLClassLoader$1.run(URLClassLoader.java:368) ~[na:1.8.0_60]
    at java.net.URLClassLoader$1.run(URLClassLoader.java:362) ~[na:1.8.0_60]
    at java.security.AccessController.doPrivileged(Native Method) ~[na:1.8.0_60]
    at java.net.URLClassLoader.findClass(URLClassLoader.java:361) ~[na:1.8.0_60]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_60]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:411) ~[na:1.8.0_60]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:411) ~[na:1.8.0_60]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_60]
    at java.lang.Class.forName0(Native Method) ~[na:1.8.0_60]
    at java.lang.Class.forName(Class.java:348) ~[na:1.8.0_60]
    at play.utils.Reflect$.getClass(Reflect.scala:142) ~[play_2.10-2.4.2.jar:2.4.2]
    at play.api.Plugins$$anonfun$loadPlugins$1.apply(Plugins.scala:88) ~[play_2.10-2.4.2.jar:2.4.2]
    at play.api.Plugins$$anonfun$loadPlugins$1.apply(Plugins.scala:87) ~[play_2.10-2.4.2.jar:2.4.2]
    at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244) ~[scala-library-2.10.5.jar:na]
    at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244) ~[scala-library-2.10.5.jar:na]
    at scala.collection.immutable.List.foreach(List.scala:318) ~[scala-library-2.10.5.jar:na]
    at scala.collection.TraversableLike$class.map(TraversableLike.scala:244) ~[scala-library-2.10.5.jar:na]
    at scala.collection.AbstractTraversable.map(Traversable.scala:105) ~[scala-library-2.10.5.jar:na]
    at play.api.Plugins$.loadPlugins(Plugins.scala:87) ~[play_2.10-2.4.2.jar:2.4.2]
    at play.api.Plugins$$anonfun$apply$4.apply(Plugins.scala:100) ~[play_2.10-2.4.2.jar:2.4.2]
    at play.api.Plugins$$anonfun$apply$4.apply(Plugins.scala:100) ~[play_2.10-2.4.2.jar:2.4.2]
    at play.api.Plugins.thePlugins$lzycompute(Plugins.scala:59) ~[play_2.10-2.4.2.jar:2.4.2]
    at play.api.Plugins.thePlugins(Plugins.scala:59) ~[play_2.10-2.4.2.jar:2.4.2]
    at play.api.Plugins.length(Plugins.scala:60) ~[play_2.10-2.4.2.jar:2.4.2]
    at scala.collection.IndexedSeqLike$class.iterator(IndexedSeqLike.scala:91) ~[scala-library-2.10.5.jar:na]
    at play.api.Plugins.iterator(Plugins.scala:57) ~[play_2.10-2.4.2.jar:2.4.2]
    at scala.collection.IterableLike$class.foreach(IterableLike.scala:72) ~[scala-library-2.10.5.jar:na]
    at play.api.Plugins.foreach(Plugins.scala:57) ~[play_2.10-2.4.2.jar:2.4.2]
    at play.api.Play$$anonfun$start$1.apply$mcV$sp(Play.scala:92) ~[play_2.10-2.4.2.jar:2.4.2]
    at play.api.Play$$anonfun$start$1.apply(Play.scala:87) ~[play_2.10-2.4.2.jar:2.4.2]
    at play.api.Play$$anonfun$start$1.apply(Play.scala:87) ~[play_2.10-2.4.2.jar:2.4.2]
    at play.utils.Threads$.withContextClassLoader(Threads.scala:21) ~[play_2.10-2.4.2.jar:2.4.2]
    at play.api.Play$.start(Play.scala:87) ~[play_2.10-2.4.2.jar:2.4.2]
    at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(DevServerStart.scala:156) ~[play-server_2.10-2.4.2.jar:2.4.2]
    ... 14 common frames omitted
Caused by: java.lang.ClassNotFoundException: play.api.cache.CachePlugin
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_60]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_60]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_60]
    ... 53 common frames omitted

And I'm stumped. At no point do I see where this problem originates. Also, it appears the old "play dependencies" command, providing that nice ASCII chart of what version of what jar was needed by which other dependency, is gone. The current "show allDependencies" is just a list of the things I have listed in my sbt file as dependencies.

EDIT:

As requested, after changing all dependencies to 2.11.7, and the scalaVersion in the build.sbt file, I get this:

[error] Modules were resolved with conflicting cross-version suffixes in {file:/home/.../}...:
[error]    com.typesafe.akka:akka-actor _2.10, _2.11
[error]    com.typesafe.play:twirl-api _2.10, _2.11
java.lang.RuntimeException: Conflicting cross-version suffixes in: com.typesafe.akka:akka-actor, com.typesafe.play:twirl-api
    at scala.sys.package$.error(package.scala:27)
    at sbt.ConflictWarning$.processCrossVersioned(ConflictWarning.scala:46)
    at sbt.ConflictWarning$.apply(ConflictWarning.scala:32)
    at sbt.Classpaths$$anonfun$66.apply(Defaults.scala:1164)
    at sbt.Classpaths$$anonfun$66.apply(Defaults.scala:1161)
    at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
    at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:40)
    at sbt.std.Transform$$anon$4.work(System.scala:63)
    at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:226)
    at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:226)
    at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:17)
    at sbt.Execute.work(Execute.scala:235)
    at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:226)
    at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:226)
    at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:159)
    at sbt.CompletionService$$anon$2.call(CompletionService.scala:28)
    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] (*:update) Conflicting cross-version suffixes in: com.typesafe.akka:akka-actor, com.typesafe.play:twirl-api

EDIT2: build.properties:

sbt.version=0.13.8

plugins.sbt:

// Comment to get more information during initialization
logLevel := Level.Warn

// The Play plugin
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.4.2")

// The Typesafe repository
resolvers ++= Seq(
  "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/",
  "Public SBT repo" at "http://dl.bintray.com/sbt/sbt-plugin-releases/",
  "Local maven repo" at "file://"+Path.userHome.absolutePath+"/.m2/repository"
)
// The eclipse plugin
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "4.0.0")

// 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(SbtEbean). Note, uncommenting this line will automatically bring in
// Play enhancer, regardless of whether the line above is commented out or not.
addSbtPlugin("com.typesafe.sbt" % "sbt-play-ebean" % "1.0.0")

build.sbt:

lazy val buildSettings = Seq(
  scalaVersion := "2.11.7"
)

lazy val root = (project in file(".")).enablePlugins(PlayJava, PlayEbean, SbtTwirl)
  .settings(buildSettings: _*)

libraryDependencies ++= Seq(
  javaJdbc,
  cache,
  javaWs,

  "net.spy" % "spymemcached" % "2.12.0",
  "com.github.mumoshu" %% "play2-memcached-play24" % "0.7.0",
  "org.apache.commons" % "commons-collections4" % "4.0"
)

EDIT2: Output after removing SbtTwirl from build.sbt:

[error] Modules were resolved with conflicting cross-version suffixes in {file:/home/.../}...:
[error]    com.typesafe.play:play-ws _2.11, _2.10
[error]    com.typesafe.play:play-functional _2.11, _2.10
[error]    com.typesafe.akka:akka-actor _2.11, _2.10
[error]    com.typesafe.play:play-java-ws _2.11, _2.10
[error]    com.typesafe.play:play-json _2.11, _2.10
[error]    com.typesafe.play:play _2.11, _2.10
[error]    com.typesafe.play:play-cache _2.11, _2.10
[error]    com.typesafe.play:play-server _2.11, _2.10
[error]    com.typesafe.play:play-java-jdbc _2.11, _2.10
[error]    com.typesafe.play:play-iteratees _2.11, _2.10
[error]    com.typesafe.play:twirl-api _2.11, _2.10
[error]    com.typesafe.play:play-jdbc _2.11, _2.10
[error]    com.typesafe.play:play-java _2.11, _2.10
[error]    com.typesafe.play:play-netty-server _2.11, _2.10
[error]    org.scala-lang.modules:scala-java8-compat _2.11, _2.10
[error]    com.typesafe.akka:akka-slf4j _2.11, _2.10
[error]    org.scala-stm:scala-stm _2.11, _2.10
[error]    com.github.mumoshu:play2-memcached-play24 _2.11, _2.10
[error]    com.typesafe.play:play-datacommons _2.11, _2.10
[error]    com.typesafe.play:play-jdbc-api _2.11, _2.10
java.lang.RuntimeException: Conflicting cross-version suffixes in: com.typesafe.play:play-ws, com.typesafe.play:play-functional, com.typesafe.akka:akka-actor, com.typesafe.play:play-java-ws, com.typesafe.play:play-json, com.typesafe.play:play, com.typesafe.play:play-cache, com.typesafe.play:play-server, com.typesafe.play:play-java-jdbc, com.typesafe.play:play-iteratees, com.typesafe.play:twirl-api, com.typesafe.play:play-jdbc, com.typesafe.play:play-java, com.typesafe.play:play-netty-server, org.scala-lang.modules:scala-java8-compat, com.typesafe.akka:akka-slf4j, org.scala-stm:scala-stm, com.github.mumoshu:play2-memcached-play24, com.typesafe.play:play-datacommons, com.typesafe.play:play-jdbc-api
    at scala.sys.package$.error(package.scala:27)
    at sbt.ConflictWarning$.processCrossVersioned(ConflictWarning.scala:46)
    at sbt.ConflictWarning$.apply(ConflictWarning.scala:32)
    at sbt.Classpaths$$anonfun$66.apply(Defaults.scala:1164)
    at sbt.Classpaths$$anonfun$66.apply(Defaults.scala:1161)
    at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
    at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:40)
    at sbt.std.Transform$$anon$4.work(System.scala:63)
    at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:226)
    at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:226)
    at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:17)
    at sbt.Execute.work(Execute.scala:235)
    at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:226)
    at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:226)
    at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:159)
    at sbt.CompletionService$$anon$2.call(CompletionService.scala:28)
    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] (*:update) Conflicting cross-version suffixes in: com.typesafe.play:play-ws, com.typesafe.play:play-functional, com.typesafe.akka:akka-actor, com.typesafe.play:play-java-ws, com.typesafe.play:play-json, com.typesafe.play:play, com.typesafe.play:play-cache, com.typesafe.play:play-server, com.typesafe.play:play-java-jdbc, com.typesafe.play:play-iteratees, com.typesafe.play:twirl-api, com.typesafe.play:play-jdbc, com.typesafe.play:play-java, com.typesafe.play:play-netty-server, org.scala-lang.modules:scala-java8-compat, com.typesafe.akka:akka-slf4j, org.scala-stm:scala-stm, com.github.mumoshu:play2-memcached-play24, com.typesafe.play:play-datacommons, com.typesafe.play:play-jdbc-api

回答1:


I think you need to enable MemCachedModule and Disable EhCacheModule

play.modules.enabled+="com.github.mumoshu.play2.memcached.MemcachedModule"
play.modules.disabled+="play.api.cache.EhCacheModule"

Please review configuration @ https://github.com/mumoshu/play2-memcached

Another suggestion Is:

The Play works in 2.4 it totally different from 2.2. The initialization has been totally changed with Guice DI coming into it.

Plugins should be migrated to Modules.

There is no CachePlugin class from Play 2.4.* onwards

Play tells:

Note: Scala 2.10 does not have full support to all Java 8 language features, like static methods on interfaces. If your project has Java code using these new features present in Java 8, upgrade to use Scala 2.11.6+. See sbt docs to learn how to set scalaVersion to your project.




回答2:


If you are using play 2.4, you should change your scala version to 2.11 . That might be what's causing your dependency problems.




回答3:


I would suggest you try and upgrade to Play 2.3.x first. Once its all good, then, upgrade to 2.4.x The difference between 2.3 and 2.4 alone is quite big and I remember I had to switch from Build.scala to build.sbt at some point

So, there might be a few conflicts down the line that you wouldn't notice till you do an incremental upgrade.



来源:https://stackoverflow.com/questions/34107490/play-framework-2-4-noclassdeffounderror-play-api-cache-cacheplugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!