2014-10-01 3 views
0

타사 클래스 (직렬화 가능하지 않음)를 직렬화하려고하며 xstream을 사용하고 있습니다.자바 - Xstream을 사용하여 직렬화 할 수없는 객체 직렬화

처음에는 제대로 작동하는지 모든 것이 잘되는지 확인하기 위해 클래스를 만들려고했지만 타사 인스턴스를 xml로 변환하려고 시도했을 때 예외가 발생했습니다.

코드 :

import java.util.List; 
import java.util.Set; 
import java.io.ByteArrayInputStream; 
import java.io.InputStream; 
import java.io.FileInputStream; 
import java.io.FileOutputStream; 
import java.io.PrintStream; 
import java.io.*; 
import java.util.*; 
import java.util.logging.*; 
import com.thoughtworks.xstream.XStream; 
import com.thoughtworks.xstream.io.xml.DomDriver; 
import vohmm.application.SimpleTagger3; 

public class Tagger{ 

    public static void main(String[] args) { 
     try { 
      SimpleTagger3 tagger = new SimpleTagger3(args[0]); 
      XStream xStream = new XStream(new DomDriver()); 

      String tagger_xml = xStream.toXML(tagger); 
     } catch (Exception e) { 
      e.printStackTrace(); 
      System.exit(0); 
     } 
    } 
} 

예외 :

Exception in thread "main" java.lang.NoClassDefFoundError: com/sleepycat/je/DatabaseException 
    at java.lang.Class.getDeclaredMethods0(Native Method) 
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2570) 
    at java.lang.Class.getDeclaredMethod(Class.java:2002) 
    at com.thoughtworks.xstream.converters.reflection.SerializationMethodInvoker.getMethod(SerializationMethodInvoker.java:164) 
    at com.thoughtworks.xstream.converters.reflection.SerializationMethodInvoker.getMethod(SerializationMethodInvoker.java:148) 
    at com.thoughtworks.xstream.converters.reflection.SerializationMethodInvoker.supportsReadObject(SerializationMethodInvoker.java:105) 
    at com.thoughtworks.xstream.converters.reflection.SerializableConverter.isSerializable(SerializableConverter.java:107) 
    at com.thoughtworks.xstream.converters.reflection.SerializableConverter.canConvert(SerializableConverter.java:103) 
    at com.thoughtworks.xstream.core.DefaultConverterLookup.lookupConverterForType(DefaultConverterLookup.java:56) 
    at com.thoughtworks.xstream.XStream$1.lookupConverterForType(XStream.java:498) 
    at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:48) 
    at com.thoughtworks.xstream.core.AbstractReferenceMarshaller$1.convertAnother(AbstractReferenceMarshaller.java:84) 
    at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshallField(AbstractReflectionConverter.java:250) 
    at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$2.writeField(AbstractReflectionConverter.java:226) 
    at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$2.<init>(AbstractReflectionConverter.java:189) 
    at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doMarshal(AbstractReflectionConverter.java:135) 
    at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshal(AbstractReflectionConverter.java:83) 
    at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:69) 
    at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:58) 
    at com.thoughtworks.xstream.core.AbstractReferenceMarshaller$1.convertAnother(AbstractReferenceMarshaller.java:84) 
    at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshallField(AbstractReflectionConverter.java:250) 
    at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$2.writeField(AbstractReflectionConverter.java:226) 
    at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$2.<init>(AbstractReflectionConverter.java:189) 
    at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doMarshal(AbstractReflectionConverter.java:135) 
    at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshal(AbstractReflectionConverter.java:83) 
    at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:69) 
    at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:58) 
    at com.thoughtworks.xstream.core.AbstractReferenceMarshaller$1.convertAnother(AbstractReferenceMarshaller.java:84) 
    at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshallField(AbstractReflectionConverter.java:250) 
    at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$2.writeField(AbstractReflectionConverter.java:226) 
    at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$2.<init>(AbstractReflectionConverter.java:189) 
    at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doMarshal(AbstractReflectionConverter.java:135) 
    at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshal(AbstractReflectionConverter.java:83) 
    at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:69) 
    at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:58) 
    at com.thoughtworks.xstream.core.AbstractReferenceMarshaller$1.convertAnother(AbstractReferenceMarshaller.java:84) 
    at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshallField(AbstractReflectionConverter.java:250) 
    at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$2.writeField(AbstractReflectionConverter.java:226) 
    at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$2.<init>(AbstractReflectionConverter.java:189) 
    at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doMarshal(AbstractReflectionConverter.java:135) 
    at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.marshal(AbstractReflectionConverter.java:83) 
    at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:69) 
    at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:58) 
    at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:43) 
    at com.thoughtworks.xstream.core.TreeMarshaller.start(TreeMarshaller.java:82) 
    at com.thoughtworks.xstream.core.AbstractTreeMarshallingStrategy.marshal(AbstractTreeMarshallingStrategy.java:37) 
    at com.thoughtworks.xstream.XStream.marshal(XStream.java:1022) 
    at com.thoughtworks.xstream.XStream.marshal(XStream.java:1011) 
    at com.thoughtworks.xstream.XStream.toXML(XStream.java:984) 
    at com.thoughtworks.xstream.XStream.toXML(XStream.java:971) 
    at NewDemo.main(NewDemo.java:51) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:606) 
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134) 
Caused by: java.lang.ClassNotFoundException: com.sleepycat.je.DatabaseException 
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366) 
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354) 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425) 
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358) 
    ... 56 more 

는 XStream을이 SimpleTagger3 작동하지 않습니다 왜 resone이 있습니까? 자바 객체를 내보내는 다른 방법이 있습니까?

+0

추적을 보면 나는 당신이 의존성을 놓친다 고 말할 것입니다. – user2504380

답변

0

클래스 로더가 'com.sleepycat.je.DatabaseException'클래스를로드하지 못했습니다. 이 클래스를 사용할 수 있는지 확인하십시오. 클래스가 사용 가능한지 테스트하려면 Class.forName("com.sleepycat.je.DatabaseException")을 시도하십시오. 클래스 경로에 추가하지 않거나 ClassLoader로로드하십시오.

+0

ClassLoader로 어떻게로드합니까? 그 수업을 어디에서 찾을 수 있습니까? – tal

+0

클래스를 'Berkeley DB Java Edition'의 일부로 찾았으므로이 프로젝트의 .jar 파일을 찾으십시오. loadClass ("")'새로운 URLClassLoader (new URL [] {new URL ("")})로로드 할 수 있습니다. ClassLoader. – kaetzacoatl