java找不到jaxb_java-为什么在Apache Felix中运行时JAXB找不到我的jaxb.index?

就在那儿,它应该在包中建立索引。 不过,当我打电话时

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

我得到一个JAXBException说

“ my.package.name”不包含ObjectFactory.class或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)内部),但是由于源不在这里,所以我看不到发生了什么。

预计到达时间:

从ContentFactory的源代码来看,我在这里发现,这可能是一段代码无法按预期工作:

/**

* 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;

}

根据我以前的经验,我猜想这与正在运行的OSGi容器的类加载机制有关。不幸的是,我在这里还不够深入。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值