Caused by: java.lang.ClassNotFoundException: com.sun.xml.bind.v2.model.annotation.AnnotationReader

前端 未结 5 1421
暖寄归人
暖寄归人 2020-12-09 15:25

You might think that following issue is very simple, but I don\'t know what I did wrong here. I feel I added required dependencies. Haven\'t I?

Could anyone please s

5条回答
  •  南方客
    南方客 (楼主)
    2020-12-09 15:57

    You seem to be running it inside the IDE. For some strange reasons, although the JAXB classes are included in JRE's rt.jar,

    ➜  lib jar tvf rt.jar| grep AnnotationReader
      4199 Fri Jan 29 15:35:18 PST 2016 com/sun/xml/internal/bind/v2/model/annotation/AbstractInlineAnnotationReaderImpl.class
      3140 Fri Jan 29 15:35:14 PST 2016 com/sun/xml/internal/bind/v2/model/annotation/AnnotationReader.class
       442 Fri Jan 29 15:35:14 PST 2016 com/sun/xml/internal/bind/v2/model/annotation/RuntimeAnnotationReader.class
      9846 Fri Jan 29 15:35:22 PST 2016 com/sun/xml/internal/bind/v2/model/annotation/RuntimeInlineAnnotationReader.class
      1217 Fri Jan 29 15:35:26 PST 2016 com/sun/xml/internal/ws/model/ReflectAnnotationReader$1.class
      1332 Fri Jan 29 15:35:26 PST 2016 com/sun/xml/internal/ws/model/ReflectAnnotationReader$2.class
      1278 Fri Jan 29 15:35:26 PST 2016 com/sun/xml/internal/ws/model/ReflectAnnotationReader$3.class
      1166 Fri Jan 29 15:35:26 PST 2016 com/sun/xml/internal/ws/model/ReflectAnnotationReader$4.class
      3563 Fri Jan 29 15:35:26 PST 2016 com/sun/xml/internal/ws/model/ReflectAnnotationReader.class
    

    they are not available for your app at runtime.

    However, if I run the app this way:

    ➜  target java -cp ./classes com.misc.common.ReadXMLFileJaxb
    Book [firstName=null, lastName=Blo, age=33]
    

    i.e. from the command line using the standard Maven structure, it does seem to run.

    Your book.xml is somewhat wrong, I believe. It contains an embedded person element whereas the Book.java does not. You may want to fix that.

提交回复
热议问题