【发布时间】:2010-11-05 19:11:04
【问题描述】:
它就在那里,在它应该被索引的包中。不过,当我打电话时
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 的源代码来看,我找到了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<Class> 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;
}
从我的previousexperience 来看,我猜测这与运行它的 OSGi 容器的类加载机制有关。不幸的是,我在这里仍然有点不够深入。
【问题讨论】:
-
我的意思是请发布异常堆栈跟踪。
-
帖子已经有点长了,但我已经追踪到异常的来源,刚刚在上面发布。
标签: java jaxb osgi apache-felix