为什么NoClassDefFoundError抛出“run”但与“dist”一起工作正常?

时间:2015-01-06 11:43:07

标签: scala playframework-2.0 h2 slick jts

在我提出这个问题之前,我已经阅读了问题Play framework java.lang.NoClassDefFoundError only in dev mode和其他几个帖子。他们没有帮助我解决我的问题。

我使用Typesafe Activator 1.2.12和play-scala模板创建了一个项目。我也使用了Slick 2.1.0。

我想在h2gis扩展中嵌入h2数据库。

使用activator run启动Play项目时,浏览器中会显示以下Execution exception

enter image description here

控制台上有以下堆栈跟踪:

18013 [play-akka.actor.default-dispatcher-3] ERROR application -

! @6kmnab7c4 - Internal server error, for (GET) [/2] ->

@6kmnab7c4: Execution exception in null:null
    at play.api.Application$class.handleError(Application.scala:296)
    at play.api.DefaultApplication.handleError(Application.scala:402)
    at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$14$$anonfun$apply$1.applyOrElse(PlayDefaultUpstreamHandler.scala:205)
    at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$14$$anonfun$apply$1.applyOrElse(PlayDefaultUpstreamHandler.scala:202)
    at scala.runtime.AbstractPartialFunction.apply(AbstractPartialFunction.scala:36)
    at scala.util.Failure$$anonfun$recover$1.apply(Try.scala:215)
    at scala.util.Try$.apply(Try.scala:191)
    at scala.util.Failure.recover(Try.scala:215)
    at scala.concurrent.Future$$anonfun$recover$1.apply(Future.scala:324)
    at scala.concurrent.Future$$anonfun$recover$1.apply(Future.scala:324)
    at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:32)
    at play.api.libs.iteratee.Execution$trampoline$.execute(Execution.scala:46)
    at scala.concurrent.impl.CallbackRunnable.executeWithValue(Promise.scala:40)
    at scala.concurrent.impl.Promise$DefaultPromise.tryComplete(Promise.scala:248)
    at scala.concurrent.Promise$class.complete(Promise.scala:55)
    at scala.concurrent.impl.Promise$DefaultPromise.complete(Promise.scala:153)
    at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:23)
    at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:41)
    at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(AbstractDispatcher.scala:393)
    at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
    at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
    at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
    at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)
Caused by: java.lang.RuntimeException: java.lang.NoClassDefFoundError: com/vividsolutions/jts/io/ParseException
    at play.api.mvc.ActionBuilder$$anon$1.apply(Action.scala:523)
    at play.api.mvc.Action$$anonfun$apply$1$$anonfun$apply$4$$anonfun$apply$5.apply(Action.scala:130)
    at play.api.mvc.Action$$anonfun$apply$1$$anonfun$apply$4$$anonfun$apply$5.apply(Action.scala:130)
    at play.utils.Threads$.withContextClassLoader(Threads.scala:21)
    at play.api.mvc.Action$$anonfun$apply$1$$anonfun$apply$4.apply(Action.scala:129)
    at play.api.mvc.Action$$anonfun$apply$1$$anonfun$apply$4.apply(Action.scala:128)
    at scala.Option.map(Option.scala:145)
    at play.api.mvc.Action$$anonfun$apply$1.apply(Action.scala:128)
    at play.api.mvc.Action$$anonfun$apply$1.apply(Action.scala:121)
    at play.api.libs.iteratee.DoneIteratee$$anonfun$mapM$2.apply(Iteratee.scala:705)
    at play.api.libs.iteratee.DoneIteratee$$anonfun$mapM$2.apply(Iteratee.scala:705)
    at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1$1(Future.scala:24)
    at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24)
    ... 6 more
Caused by: java.lang.NoClassDefFoundError: com/vividsolutions/jts/io/ParseException
    at org.h2.value.DataType.convertToValue(DataType.java:1039)
    at org.h2.engine.FunctionAlias$JavaMethod.getValue(FunctionAlias.java:500)
    at org.h2.expression.JavaFunction.getValue(JavaFunction.java:39)
    at org.h2.expression.JavaFunction.optimize(JavaFunction.java:63)
    at org.h2.expression.JavaFunction.optimize(JavaFunction.java:58)
    at org.h2.expression.Function.optimize(Function.java:2104)
    at org.h2.command.dml.Select.prepare(Select.java:831)
    at org.h2.command.Parser.prepareCommand(Parser.java:248)
    at org.h2.engine.Session.prepareLocal(Session.java:442)
    at org.h2.engine.Session.prepareCommand(Session.java:384)
    at org.h2.jdbc.JdbcConnection.prepareCommand(JdbcConnection.java:1188)
    at org.h2.jdbc.JdbcPreparedStatement.<init>(JdbcPreparedStatement.java:73)
    at org.h2.jdbc.JdbcConnection.prepareStatement(JdbcConnection.java:665)
    at scala.slick.jdbc.JdbcBackend$SessionDef$class.prepareStatement(JdbcBackend.scala:152)
    at scala.slick.jdbc.JdbcBackend$BaseSession.prepareStatement(JdbcBackend.scala:389)
    at scala.slick.jdbc.StatementInvoker.results(StatementInvoker.scala:32)
    at scala.slick.jdbc.StatementInvoker.iteratorTo(StatementInvoker.scala:22)
    at scala.slick.jdbc.Invoker$class.foreach(Invoker.scala:64)
    at scala.slick.jdbc.StatementInvoker.foreach(StatementInvoker.scala:16)
    at scala.slick.jdbc.Invoker$class.firstOption(Invoker.scala:29)
    at scala.slick.jdbc.StatementInvoker.firstOption(StatementInvoker.scala:16)
    at scala.slick.jdbc.Invoker$class.first(Invoker.scala:36)
    at scala.slick.jdbc.StatementInvoker.first(StatementInvoker.scala:16)
    at controllers.Application$$anonfun$hi$1$Global$2$$anonfun$onStart$1.apply(Application.scala:45)
    at controllers.Application$$anonfun$hi$1$Global$2$$anonfun$onStart$1.apply(Application.scala:39)
    at scala.slick.backend.DatabaseComponent$DatabaseDef$class.withSession(DatabaseComponent.scala:34)
    at scala.slick.jdbc.JdbcBackend$DatabaseFactoryDef$$anon$4.withSession(JdbcBackend.scala:61)
    at controllers.Application$$anonfun$hi$1$Global$2$.onStart(Application.scala:39)
    at controllers.Application$$anonfun$hi$1.apply(Application.scala:61)
    at controllers.Application$$anonfun$hi$1.apply(Application.scala:27)
    at play.api.mvc.ActionBuilder$$anonfun$apply$17.apply(Action.scala:464)
    at play.api.mvc.ActionBuilder$$anonfun$apply$17.apply(Action.scala:464)
    at play.api.mvc.ActionBuilder$$anonfun$apply$16.apply(Action.scala:433)
    at play.api.mvc.ActionBuilder$$anonfun$apply$16.apply(Action.scala:432)
    at play.api.mvc.Action$.invokeBlock(Action.scala:556)
    at play.api.mvc.Action$.invokeBlock(Action.scala:555)
    at play.api.mvc.ActionBuilder$$anon$1.apply(Action.scala:518)
    ... 18 more
Caused by: java.lang.ClassNotFoundException: com.vividsolutions.jts.io.ParseException
    at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 55 more

但是,如果我执行activator dist,并运行应用程序它运作良好(!)

h2的jar文件位于lib和sbt的引用中,不使用h2gis,不会发生错误。

项目的源代码在GitHub上作为weird-error项目。使用该项目来面对错误。

更新

以下是带有命令./activator run -J-XX:+TraceClassLoading的跟踪输出 我只粘贴了它的一部分,似乎CoordinateArraySequence引发了异常。

[Loaded scala.slick.util.ReadAheadIterator$class from file:/Users/myusername/.ivy2/cache/com.typesafe.slick/slick_2.11/bundles/slick_2.11-2.1.0.jar]
[Loaded scala.slick.jdbc.SQLInterpolation$ from file:/Users/myusername/.ivy2/cache/com.typesafe.slick/slick_2.11/bundles/slick_2.11-2.1.0.jar]
[Loaded scala.slick.jdbc.SQLInterpolationResult from file:/Users/myusername/.ivy2/cache/com.typesafe.slick/slick_2.11/bundles/slick_2.11-2.1.0.jar]
[Loaded scala.slick.jdbc.GetResult$GetString$ from file:/Users/myusername/.ivy2/cache/com.typesafe.slick/slick_2.11/bundles/slick_2.11-2.1.0.jar]
[Loaded scala.slick.jdbc.Invoker$$anonfun$firstOption$1 from file:/Users/myusername/.ivy2/cache/com.typesafe.slick/slick_2.11/bundles/slick_2.11-2.1.0.jar]
[Loaded com.vividsolutions.jts.io.WKTReader from file:/Users/myusername/p/scala/weird-error/lib/jts-1.13.jar]
[Loaded com.vividsolutions.jts.geom.impl.CoordinateArraySequence from file:/Users/myusername/p/scala/weird-error/lib/jts-1.13.jar]
[Loaded com.vividsolutions.jts.util.Assert from file:/Users/myusername/p/scala/weird-error/lib/jts-1.13.jar]
[Loaded com.vividsolutions.jts.util.AssertionFailedException from file:/Users/myusername/p/scala/weird-error/lib/jts-1.13.jar]
[Loaded scala.util.Failure$$anonfun$recover$1 from file:/Users/myusername/.ivy2/cache/org.scala-lang/scala-library/jars/scala-library-2.11.1.jar]
[Loaded play.api.Application$$anonfun$4 from file:/Users/myusername/.ivy2/cache/com.typesafe.play/play_2.11/jars/play_2.11-2.3.7.jar]
[Loaded play.core.SourceMapper$$anonfun$sourceFor$1 from file:/Users/myusername/.ivy2/cache/com.typesafe.play/play_2.11/jars/play_2.11-2.3.7.jar]
[Loaded scala.collection.IndexedSeqOptimized$$anonfun$1 from file:/Users/myusername/.ivy2/cache/org.scala-lang/scala-library/jars/scala-library-2.11.1.jar]
[Loaded play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1$$anonfun$1$$anon$1$$anon$2$$anonfun$sourceOf$1 from file:/Users/myusername/.ivy2/cache/com.typesafe.pla
y/play_2.11/jars/play_2.11-2.3.7.jar]
[Loaded scala.Option$$anonfun$orNull$1 from file:/Users/myusername/.ivy2/cache/org.scala-lang/scala-library/jars/scala-library-2.11.1.jar]
[Loaded play.PlayReloader$$anon$1$$anonfun$findSource$1 from file:/Users/myusername/.ivy2/cache/scala_2.10/sbt_0.13/com.typesafe.play/sbt-plugin/jars/sbt-plugin-2.3.7.jar]
[Loaded play.PlayReloader$$anon$1$$anonfun$findSource$1$$anonfun$apply$8 from file:/Users/myusername/.ivy2/cache/scala_2.10/sbt_0.13/com.typesafe.play/sbt-plugin/jars/sbt-plug
in-2.3.7.jar]
[Loaded play.PlayReloader$$anon$1$$anonfun$findSource$1$$anonfun$apply$8$$anonfun$apply$9 from file:/Users/myusername/.ivy2/cache/scala_2.10/sbt_0.13/com.typesafe.play/sbt-plu
gin/jars/sbt-plugin-2.3.7.jar]
[Loaded play.PlayReloader$$anon$1$$anonfun$findSource$1$$anonfun$apply$8$$anonfun$apply$10 from file:/Users/myusername/.ivy2/cache/scala_2.10/sbt_0.13/com.typesafe.play/sbt-pl
ugin/jars/sbt-plugin-2.3.7.jar]
[Loaded play.PlayReloader$$anon$1$$anonfun$findSource$1$$anonfun$apply$11 from file:/Users/myusername/.ivy2/cache/scala_2.10/sbt_0.13/com.typesafe.play/sbt-plugin/jars/sbt-plu
gin-2.3.7.jar]
[Loaded play.PlayReloader$$anon$1$$anonfun$findSource$2 from file:/Users/myusername/.ivy2/cache/scala_2.10/sbt_0.13/com.typesafe.play/sbt-plugin/jars/sbt-plugin-2.3.7.jar]
[Loaded play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1$$anonfun$1$$anon$1$$anon$2$$anonfun$sourceOf$2 from file:/Users/myusername/.ivy2/cache/com.typesafe.pla
y/play_2.11/jars/play_2.11-2.3.7.jar]
[Loaded play.core.SourceMapper$$anonfun$sourceFor$2 from file:/Users/myusername/.ivy2/cache/com.typesafe.play/play_2.11/jars/play_2.11-2.3.7.jar]
[Loaded play.api.Application$$anonfun$handleError$1 from file:/Users/myusername/.ivy2/cache/com.typesafe.play/play_2.11/jars/play_2.11-2.3.7.jar]
[Loaded play.api.Application$$anonfun$handleError$2 from file:/Users/myusername/.ivy2/cache/com.typesafe.play/play_2.11/jars/play_2.11-2.3.7.jar]
[Loaded scala.collection.immutable.StringLike$$anon$1 from file:/Users/myusername/.ivy2/cache/org.scala-lang/scala-library/jars/scala-library-2.11.1.jar]
[Loaded scala.collection.immutable.StringLike$$anonfun$stripMargin$1 from file:/Users/myusername/.ivy2/cache/org.scala-lang/scala-library/jars/scala-library-2.11.1.jar]
18361 [play-akka.actor.default-dispatcher-2] ERROR application -

! @6kpj6pec5 - Internal server error, for (GET) [/2] ->

1 个答案:

答案 0 :(得分:1)

尝试将这些依赖项添加到build.sbt文件中,而不是将jar放在lib中。

"com.typesafe.slick" %% "slick" % "2.1.0",
"org.orbisgis" % "h2gis" % "1.1.0",
"com.vividsolutions" % "jts" % "1.13"

在开发模式下,播放sbt将使用多个类加载器来支持热重新加载,而在dist之后,只有一个类加载器来处理你的项目。话虽如此,把所有东西都放在同一个地方可能会解决你的问题。