【问题标题】:JBoss Serialization and `NoClassDefFoundError`JBoss 序列化和`NoClassDefFoundError`
【发布时间】:2014-05-11 13:42:53
【问题描述】:

我正在尝试使用 JBoss Serialization 来存储我的对象,这是我的帮手:

object JBoss {
  def toBytes(exe: Any) = {
    val baos = new ByteArrayOutputStream
    val oos = new JBossObjectOutputStream(baos)
    (oos writeObject exe, oos flush, oos close, baos close)
    baos.toByteArray
  }

  // Object in byte form
  type ByteObj = Array[Byte]

  def to[T](exe: ByteObj) = {
    val bais = new ByteArrayInputStream(exe)
    val ois = new JBossObjectInputStream(bais)
    val rs = ois.readObject.asInstanceOf[T]
    ois.close
    rs
  }
}

当我尝试这样使用它时:

try {
  class A(val x: String, s: String) { override def toString = s"A(x = $x, s = $s)" }
  val bytes = JBoss.toBytes(new A("one", "two"))
} catch {
  case e: Throwable => println(e)
}

我收到以下异常:java.lang.NoClassDefFoundError: gnu/trove/TObjectHashingStrategy 如何解决此问题?

【问题讨论】:

    标签: scala serialization jboss


    【解决方案1】:

    因为您在运行时缺少库。 运行项目时,您应该使用 lib trove-2.1.1.jar 添加到您的类路径中。

    Trove download here

    【讨论】:

      猜你喜欢
      • 2020-12-05
      • 2022-06-11
      • 2017-01-20
      • 1970-01-01
      • 2011-08-27
      • 1970-01-01
      • 1970-01-01
      • 2022-07-01
      • 2020-01-05
      相关资源
      最近更新 更多