如何指定特定的 JAXB 实现?
似乎我过去已经做过一次这样的事,但我找不到任何关于我为使它起作用而做的事情的参考。
我有一个Web应用程序,我想在其中指定一个与我的Web服务器/ jre提供的JAXB实现不同的JAXB实现。我从maven下载了适当的工件,并看到jar在我的战争中被正确打包,但是,当我启动我的Web应用程序时,我看到它仍然使用捆绑的JRE实现。
我依稀记得一些关于我可以配置的属性文件的东西,但找不到关于如何配置它的引用。此外,如果我想使用的实现是相同的(只是一个较新的版本),则类名将与打包在JRE中的类名相同。如何指定要使用 WAR 中捆绑的那些?
编辑
我目前在JBoss 7.0.2上运行,Oracle JDK 1.6_0_27,JRE附带的JAXB RI(我认为它是v2.1)。我正在尝试升级到JAXB RI 2.2.5(在MvnRepository上找到)。
今天早上我做了更多的挖掘,并注意到我的日志中有一条奇怪的错误消息:
09:43:18,325 WARN [org.jboss.as.server.deployment] (MSC service thread 1-12) Class Path entry jaxb-api.jar in "/C:/servers/jboss-as-7.0.2.Final/standalone/deployments/LendingSimulationServiceEAR.ear/LendingSimulationService.war/WEB-INF/lib/jaxb-impl-2.2.5.jar" does not point to a valid jar for a Class-Path reference.
09:43:18,325 WARN [org.jboss.as.server.deployment] (MSC service thread 1-12) Class Path entry activation.jar in "/C:/servers/jboss-as-7.0.2.Final/standalone/deployments/LendingSimulationServiceEAR.ear/LendingSimulationService.war/WEB-INF/lib/jaxb-impl-2.2.5.jar" does not point to a valid jar for a Class-Path reference.
09:43:18,326 WARN [org.jboss.as.server.deployment] (MSC service thread 1-12) Class Path entry jsr173_1.0_api.jar in "/C:/servers/jboss-as-7.0.2.Final/standalone/deployments/LendingSimulationServiceEAR.ear/LendingSimulationService.war/WEB-INF/lib/jaxb-impl-2.2.5.jar" does not point to a valid jar for a Class-Path reference.
09:43:18,326 WARN [org.jboss.as.server.deployment] (MSC service thread 1-12) Class Path entry jaxb1-impl.jar in "/C:/servers/jboss-as-7.0.2.Final/standalone/deployments/LendingSimulationServiceEAR.ear/LendingSimulationService.war/WEB-INF/lib/jaxb-impl-2.2.5.jar" does not point to a valid jar for a Class-Path reference.
我觉得很奇怪。我不确定它在哪里可以找到这些信息。更多的研究在MANIFEST中发现了这条线。中频:
Class-Path: jaxb-api.jar activation.jar jsr173_1.0_api.jar jaxb1-impl.jar
所以现在我比以往任何时候都更加困惑。看起来jaxb实现依赖于api,activation,jsr和jaxb1实现jars。但它们没有列在jaxb pom中。网上的一些挖掘找到了这个链接,它讨论了如何在Java6SE环境中使用JAXB 2.2。不幸的是,这似乎也没有奏效。我仍然收到上述警告消息。
我使用以下代码片段来列出正在运行的 JAXB 实现;也许这是不正确的?
/**
* Print the JAXB Implementation information
*/
public static void outputJaxpImplementationInfo() {
logger.debug(getImplementationInfo("DocumentBuilderFactory", DocumentBuilderFactory.newInstance().getClass()));
logger.debug(getImplementationInfo("XPathFactory", XPathFactory.newInstance().getClass()));
logger.debug(getImplementationInfo("TransformerFactory", TransformerFactory.newInstance().getClass()));
logger.debug(getImplementationInfo("SAXParserFactory", SAXParserFactory.newInstance().getClass()));
}
/**
* Get the JAXB implementation information for a particular class
* @param componentName
* @param componentClass
* @return
*/
private static String getImplementationInfo(String componentName, Class componentClass) {
CodeSource source = componentClass.getProtectionDomain().getCodeSource();
return MessageFormat.format(
"{0} implementation: {1} loaded from: {2}",
componentName,
componentClass.getName(),
source == null ? "Java Runtime" : source.getLocation());
}
此代码段生成以下日志:
10:28:27,402 INFO [stdout] (MSC service thread 1-14) 2012-04-04 10:28:27,402 DEBUG cws.cs.lendingsimulationservice.util.JAXBUtil - DocumentBuilderFactory implementation: __redirected.__DocumentBuilderFactory loaded from: file:/C:/servers/jboss-as-7.0.2.Final/jboss-modules.jar
10:28:27,403 INFO [stdout] (MSC service thread 1-14) 2012-04-04 10:28:27,403 DEBUG cws.cs.lendingsimulationservice.util.JAXBUtil - XPathFactory implementation: __redirected.__XPathFactory loaded from: file:/C:/servers/jboss-as-7.0.2.Final/jboss-modules.jar
10:28:27,404 INFO [stdout] (MSC service thread 1-14) 2012-04-04 10:28:27,404 DEBUG cws.cs.lendingsimulationservice.util.JAXBUtil - TransformerFactory implementation: __redirected.__TransformerFactory loaded from: file:/C:/servers/jboss-as-7.0.2.Final/jboss-modules.jar
10:28:27,406 INFO [stdout] (MSC service thread 1-14) 2012-04-04 10:28:27,406 DEBUG cws.cs.lendingsimulationservice.util.JAXBUtil - SAXParserFactory implementation: __redirected.__SAXParserFactory loaded from: file:/C:/servers/jboss-as-7.0.2.Final/jboss-modules.jar