Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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
like image 670
KdgDev Avatar asked Dec 05 '15 15:12

KdgDev


1 Answers

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.

like image 193
Gajendra Naidu Avatar answered Sep 23 '22 08:09

Gajendra Naidu