java找不到jaxb_java – 为什么JAXB在Apache Felix中运行时找不到我的jaxb.in​​dex?...

它在那里,在包中,它应该索引。还是,当我打电话

JAXBContext jc = JAXBContext.newInstance("my.package.name");

我得到一个JAXBException说

“my.package.name” doesnt contain ObjectFactory.class or jaxb.index

虽然它包含两者。

什么工作,但不是我想要的,是

JAXBContext jc = JAXBContext.newInstance(my.package.name.SomeClass.class);

这个问题从各种其他人出现在相当多的邮件列表和论坛,但似乎没有得到答案。

我在OpenJDK 6上运行这个,所以我得到源包和我的调试器进入库。它从查找jaxb.properties开始,然后查找系统属性,并且也没有找到它,它尝试使用com.sun.internal.xml.bind.v2.ContextFactory创建默认上下文。在那里,异常被抛出(在ContextFactor.createContext(String ClassLoader,Map)),但我不能看到发生了什么,因为源不在这里。

ETA:

从ContentFactory的源代码判断,我发现here,这可能是一段代码无法按预期工作:

/**

* Look for jaxb.index file in the specified package and load it's contents

*

* @param pkg package name to search in

* @param classLoader ClassLoader to search in

* @return a List of Class objects to load, null if there weren't any

* @throws IOException if there is an error reading the index file

* @throws JAXBException if there are any errors in the index file

*/

private static List loadIndexedClasses(String pkg, ClassLoader classLoader) throws IOException, JAXBException {

final String resource = pkg.replace('.', '/') + "/jaxb.index";

final InputStream resourceAsStream = classLoader.getResourceAsStream(resource);

if (resourceAsStream == null) {

return null;

}

从我的previous experience,我猜这是与运行在OSGi容器的类加载机制。不幸的是,我仍然有点离我的深度。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值