JAXB技术问题

日前在使用JAXB技术生成XML文件,在Get the JAXBContext from jaxb-api.jar (2.0)

 

JAXBContext jaxbContext = JAXBContext.newInstance(schemaName); 

出现如下异常:

java.lang.LinkageError: JAXB 2.0 API is being loaded from the bootstrap classloader, but this RI (from jar:file:/D:/Genuitec/WorkSpace/GenerateSchema/WebRoot/WEB-INF/lib/jaxb-impl-2.1.6.jar!/com/sun/xml/bind/v2/model/impl/ModelBuilder.class) needs 2.1 API. Use the endorsed directory mechanism to place jaxb-api.jar in the bootstrap classloader. (See http://java.sun.com/j2se/1.5.0/docs/guide/standards/)
 at com.sun.xml.bind.v2.model.impl.ModelBuilder.<clinit>(ModelBuilder.java:173)
 at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:422)
 at com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:286)
 at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:139)
 at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:117)
 at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:188)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:597)
 at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:132)
 at javax.xml.bind.ContextFinder.find(ContextFinder.java:286)
 at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:372)
 at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:337)
 at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:244)
 at com.ys.schema.service.GenerateXMLBySchemaBase.buildXml(GenerateXMLBySchemaBase.java:63)
 at com.ys.schema.service.impl.GenerateXMLBySchemaForExchanging.generateXML(GenerateXMLBySchemaForExchanging.java:68)
 at com.ys.schema.test.TestGenerateXML.testGenerateXML(TestGenerateXML.java:44)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:597)
 at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
 at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
 at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
 at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
 at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
 at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
 at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:73)
 at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:46)
 at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:180)
 at org.junit.runners.ParentRunner.access$000(ParentRunner.java:41)
 at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java:173)
 at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
 at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
 at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
 at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
 at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

 

发现是版本要求达不到的原因,G出来的结果大致如该文所举:http://haiyupeter.iteye.com/blog/306557

 

但终未能切实解决,故而逆向回求解决之道。(既然升版本奈何不了,不如jaxb-impl.jar降低版本。

 

jre环境仍然为1.6,jaxb-api.jar仍然为2.0,但是jaxb-impl.jar由2.1.12降为2.0.1。(另意外发现:两个版本的jaxb-impl都放在lib内并无冲突)。

 

你可能感兴趣的:(xml,JAXB)