Caused by: java.lang.ClassNotFoundException: com/sun/tools/internal/xjc/api/XJC
缺少com/sun/tools/internal/xjc/api/XJC
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
蕃薯耀 2016年2月29日 14:41:19 星期一
http://fanshuyao.iteye.com/
Exception in thread "main" java.lang.IllegalStateException: Unable to create schema compiler at org.apache.cxf.common.jaxb.JAXBUtils.createSchemaCompilerWithDefaultAllocator(JAXBUtils.java:663) at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createSchemaCompiler(DynamicClientFactory.java:422) at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:306) at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:240) at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:233) at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:188) at com.lqy.spring.cxf_client.Main.main(Main.java:12) Caused by: javax.xml.bind.JAXBException - with linked exception: [java.lang.ClassNotFoundException: com/sun/tools/internal/xjc/api/XJC] at org.apache.cxf.common.jaxb.JAXBUtils.createSchemaCompiler(JAXBUtils.java:648) at org.apache.cxf.common.jaxb.JAXBUtils.createSchemaCompilerWithDefaultAllocator(JAXBUtils.java:655) ... 6 more Caused by: java.lang.ClassNotFoundException: com/sun/tools/internal/xjc/api/XJC at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Unknown Source) at org.apache.cxf.common.jaxb.JAXBUtils.createSchemaCompiler(JAXBUtils.java:641) ... 7 more
一、問題描述:
在CXF調用接口的代碼時,跳出這樣的錯誤:
Caused by: java.lang.ClassNotFoundException: com/sun/tools/internal/xjc/api/XJC
JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance(); org.apache.cxf.endpoint.Client client = dcf.createClient("http://localhost:8080/cxf/ws/getUserName?wsdl"); //sayHello 為接口中定義的方法名稱 張三為傳遞的參數 返回一個Object數組 //Object[] objects=client.invoke("getUserName", new Object[]{}); Object[] objects=client.invoke("getUserNameByString", "張三"); //輸出調用結果 System.out.println(objects[0].toString());
二、解決
但網上都說在jaxb-xjc這個Jar包里,其實是不對的,因為引用的是Jdk lib下的tools.jar
D:\Java\jdk1.6.0_45\lib\tools.jar,缺少的是這個包,把這個包引用就正常了。
三、注意
加了tools.jar,再添加jaxb-xjc也會報錯,所以不要再添加jaxb-xjc.jar。
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-xjc</artifactId>
<version>2.2.11</version>
</dependency>
Exception in thread "main" java.lang.IllegalStateException: Unable to write generated Java files for schemas: null at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:354) at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:240) at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:233) at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:188) at com.lqy.spring.cxf_client.Main.main(Main.java:12) Caused by: java.lang.reflect.UndeclaredThrowableException at com.sun.proxy.$Proxy27.build(Unknown Source) at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:352) ... 4 more Caused by: java.lang.NoSuchMethodException: com.sun.codemodel.internal.JCodeModel.build(java.lang.Object) at java.lang.Class.getMethod(Unknown Source) at org.apache.cxf.common.util.ReflectionInvokationHandler.invoke(ReflectionInvokationHandler.java:85) ... 6 more
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
蕃薯耀 2016年2月29日 14:41:19 星期一
http://fanshuyao.iteye.com/