cxf使用JaxWsDynamicClientFactory动态调用webservice异常

本人maven依赖以下(cxf.version版本为2.2.3):

        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-frontend-jaxws</artifactId>
            <version>${cxf.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-transports-http</artifactId>
            <version>${cxf.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-transports-http-jetty</artifactId>
            <version>${cxf.version}</version>
        </dependency>

使用JaxWsDynamicClientFactory动态调用,出现以下异常:

Exception in thread "main" java.lang.IllegalStateException: Unable to create schema compiler
    at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:264)
    at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:196)
    at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:189)
    at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:144)
    at com.service.run.TestService.main(TestService.java:21)
Caused by: javax.xml.bind.JAXBException
 - with linked exception:
[java.lang.ClassNotFoundException: com.sun.tools.internal.xjc.api.XJC]
    at org.apache.cxf.jaxb.JAXBUtils.createSchemaCompiler(JAXBUtils.java:622)
    at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:262)
    ... 4 more
Caused by: java.lang.ClassNotFoundException: com.sun.tools.internal.xjc.api.XJC
    at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:260)
    at org.apache.cxf.jaxb.JAXBUtils.createSchemaCompiler(JAXBUtils.java:615)
    ... 5 more
 

异常说找不到class文件,好吧,我把cxf所有依赖包导进来,maven更改为以下依赖(版本不变):

<dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>apache-cxf</artifactId>
        <version>${cxf.version}</version>
        <type>pom</type>
  </dependency>

再运行,这回不会出现以上异常了,而出现了另一个异常!!(我给您跪了):

严重: Could not compile java files for http://localhost/vashon?wsdl.
Exception in thread "main" java.lang.IllegalStateException: Unable to create JAXBContext for generated packages: Provider com.sun.xml.bind.v2.ContextFactory could not be instantiated: javax.xml.bind.JAXBException: "com.service" doesnt contain ObjectFactory.class or jaxb.index
    at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:352)
    at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:196)
    at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:189)
    at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:144)
    at com.service.run.TestService.main(TestService.java:21)
Caused by: javax.xml.bind.JAXBException: Provider com.sun.xml.bind.v2.ContextFactory could not be instantiated: javax.xml.bind.JAXBException: "com.service" doesnt contain ObjectFactory.class or jaxb.index
 - with linked exception:
[javax.xml.bind.JAXBException: "com.service" doesnt contain ObjectFactory.class or jaxb.index]
    at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:146)
    at javax.xml.bind.ContextFinder.find(ContextFinder.java:335)
    at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:431)
    at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:349)
    ... 4 more
Caused by: javax.xml.bind.JAXBException: "com.service" doesnt contain ObjectFactory.class or jaxb.index
    at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:197)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:171)
    at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:131)
    ... 7 more

经过不断的,最终发现是TMD版本导致的,我将cxf.version版本更改为3.1.7运行成功,而且使用最上方的maven依赖也运行正常。(哎~网上拿手即用的代码还是挺折腾的)

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值