JBoss Serialization和`NoClassDefFoundError`

时间:2014-05-11 13:42:54

标签: scala serialization jboss

我尝试使用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如何解决此问题?

1 个答案:

答案 0 :(得分:0)

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

Trove download here