2015年12月25日   码农之路   11,411 次浏览

javacTask: 目标发行版 1.5 与默认的源发行版 1.7 冲突
Exception in thread "main" java.lang.IllegalStateException: 
Unable to create JAXBContext for generated packages: 
Provider com.sun.xml.bind.v2.ContextFactory could not be instantiated: 
javax.xml.bind.JAXBException: "com.bd.service" doesnt contain ObjectFactory.class or jaxb.index

今天写CXF动态客户端(JaxWsDynamicClientFactory)时出现了上面这个错误,如果按照字面理解是jdk的版本不对,各种百度也是说jdk版本不对,可是我从1.5换到1.6再换到1.7,然并卵……

于是改变搜索关键词:Unable to create JAXBContext,javax.xml.bind.JAXBException,直接搜索这个异常,最后在http://stackoverflow.com/questions/7232331/unable-to-create-jaxbcontext-creating-my-wsdl发现了这么一段话:

My Maven project built just fine with JDK 6, but when I switched to be using JDK 1.7 as my default, the build broke.
Regarding the version. This bug is listed at https://java.net/jira/browse/JAXB-814. It's fixed for versions 2.2.4u2, 2.2.5, 2.3
I have resolved this issue by fixing the jaxb-impl version from 2.1.9 to 2.2.6 and it works fine now.
 
<dependency>
        <groupId>com.sun.xml.bind</groupId>
        <artifactId>jaxb-impl</artifactId>
        <version>2.2.6</version>
</dependency>

大意就是com.sun.xml.bind这个组件的低版本在jdk1.7有个bug,需要升级到最新版本,而这个组件在CXF的依赖组件中可以找到,看到我的版本才1.4,于是果断把整个CXF升级到2.7.18(2.X版本中最高的,com.sun.xml.bind对应的版本为2.2.6),重新编译(jdk1.7),代码通过。

总结:
当出现javacTask: 目标发行版 1.5 与默认的源发行版 1.7 冲突的时候,需要分析整个错误堆栈,找到错误的源头。尤其用maven来管理的时候,会产生很多依赖包表面是看不到的,需要跟踪好几个pom才能发现。

赞 赏
申明:除非注明,本站文章均为原创,转载请以链接形式标明本文地址。 如有问题,请于一周内与本站联系,本站将在第一时间对相关内容进行处理。
本文地址: http://www.yyjjssnn.cn/articles/703.html

>>> Hello World <<<

这篇内容是否帮助到你了呢?

如果你有任何疑问或有建议留给其他朋友,都可以给我留言。

目前有有一条留言:

  • 1# 6666:
    2018-09-12 11:44

    嘻嘻,问题解决!!

:wink: :twisted: :surprised: :smile: :smile9: :smile8: :smile7: :smile6: :smile5: :smile56: :smile55: :smile54: :smile53: :smile52: :smile51: :smile50: :smile4: :smile49: :smile48: :smile47: :smile46: :smile45: :smile44: :smile43: :smile42: :smile41: :smile40: :smile3: :smile39: :smile38: :smile37: :smile36: :smile35: :smile34: :smile33: :smile32: :smile31: :smile30: :smile2: :smile29: :smile28: :smile27: :smile26: :smile25: :smile24: :smile23: :smile22: :smile21: :smile20: :smile1: :smile19: :smile18: :smile17: :smile16: :smile15: :smile14: :smile13: :smile12: :smile11: :smile10: :smile0: :sad: :rolleyes1: :redface: :razz: :question: :neutral: :mrgreen: :mad: :lol: :idea: :exclaim: :evil: :eek: :cry: :cool: :confused: :biggrin: :arrow:

友情链接: 程序员刘杨 刘杨
Copyright 2003~2018 保留所有权利 | 网站地图
备案号:湘ICP备14001005号-2

湘公网安备 43011102001322号