Marshal.load 上的 ClassNotFoundException

发布于 2024-11-02 19:03:55 字数 1103 浏览 1 评论 0原文

我正在尝试在 Scala 中进行元帅转储和加载......

import scala.util.Marshal

case class Test(test: String)

val t = Test("hello")
val bytes = Marshal.dump(t)
Marshal.load[Test](bytes)

但是对 Marshal.load 的调用抛出 ClassNotFoundException...

java.lang.ClassNotFoundException: Test
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
at java.io.ObjectInputStream.resolveClass(ObjectInputStream.java:603)
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1574)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1495)
at java.io.ObjectInputStream.readClass(ObjectInputStream.java:1461)
at java.io.Ob...

我也尝试过使用完全限定的类名,但没有运气。我缺少什么?

I'm trying to do a marshal dump and load in Scala...

import scala.util.Marshal

case class Test(test: String)

val t = Test("hello")
val bytes = Marshal.dump(t)
Marshal.load[Test](bytes)

...but the call to Marshal.load is throwing a ClassNotFoundException...

java.lang.ClassNotFoundException: Test
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
at java.io.ObjectInputStream.resolveClass(ObjectInputStream.java:603)
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1574)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1495)
at java.io.ObjectInputStream.readClass(ObjectInputStream.java:1461)
at java.io.Ob...

I've also tried using the fully qualified class name but with no luck. What am I missing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

妄想挽回 2024-11-09 19:03:55

您使用的是哪个版本的 SBT?我在 SBT 0.7.7 中遇到了类似的问题,并通过将以下内容添加到我的构建中解决了这些问题:

// cause the SBT "run" action to fork                                                                                                              
override def fork = Some(new ForkScalaRun() {
  override def scalaJars = Seq(buildLibraryJar.asFile, buildCompilerJar.asFile)
})

导致“运行”操作分叉似乎可以解决类加载器问题以及捕获 System.exit 调用的问题:

http://code.google.com/p/simple-build- tool/wiki/Forking

http://code.google. com/p/simple-build-tool/wiki/RunningProjectCode

Which version of SBT are you using? I had similar problems with SBT 0.7.7 and resolved them by adding the following to my build:

// cause the SBT "run" action to fork                                                                                                              
override def fork = Some(new ForkScalaRun() {
  override def scalaJars = Seq(buildLibraryJar.asFile, buildCompilerJar.asFile)
})

Causing the "run" action to fork seems to resolve class loader problems, and problems with trapping System.exit calls:

http://code.google.com/p/simple-build-tool/wiki/Forking

http://code.google.com/p/simple-build-tool/wiki/RunningProjectCode

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文