2013-03-05 245 views
3

我有一個RestEasyClient該初始化如下,並使用JBoss作爲7.1 RestEasy的模塊RestEasy的客戶端拋出拋出java.lang.ClassNotFoundException:com.sun.ws.rs.ext.RuntimeDelegateImpl

@PostConstruct 
public void initializeClient() { 

    log.info("In initializeClient"); 
    HttpClient httpClient = new DefaultHttpClient(); 
    ClientExecutor executor = new ApacheHttpClient4Executor(httpClient); 
    ResteasyProviderFactory.getInstance().registerProvider(
      ServiceExecutionInterceptor.class); 
    clientService = ProxyFactory.create(MyProjectClientService.class, 
      getWebserviceURL(), executor); 
} 

該服務器啓動過程中拋出以下錯誤

Caused by: java.lang.ClassNotFoundException: com.sun.ws.rs.ext.RuntimeDelegateImpl from [Module "javax.ws.rs.api:main" from local module loader @5ad557c2 (roots: C:\Program Files\jboss-eap-6.0\modules)] 
    at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190) 
    at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468) 
    at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456) 
    at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:423) 
    at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398) 
    at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120) 
    at java.lang.Class.forName0(Native Method) [rt.jar:1.6.0_32] 
    at java.lang.Class.forName(Class.java:169) [rt.jar:1.6.0_32] 
    at javax.ws.rs.ext.FactoryFinder.newInstance(FactoryFinder.java:77) 
    at javax.ws.rs.ext.FactoryFinder.find(FactoryFinder.java:201) 
    at javax.ws.rs.ext.RuntimeDelegate.findDelegate(RuntimeDelegate.java:113) 

我的pom.xml如下

的pom.xml

<!-- Import the JAX-RS API, we use provided scope as the API is included 
     in JBoss AS 7 --> 
    <dependency> 
     <groupId>org.jboss.spec.javax.ws.rs</groupId> 
     <artifactId>jboss-jaxrs-api_1.1_spec</artifactId> 
     <scope>provided</scope> 
    </dependency> 

    <!-- Resteasy Dependencies --> 
    <dependency> 
     <groupId>org.jboss.resteasy</groupId> 
     <artifactId>resteasy-jaxrs</artifactId> 
     <version>${resteasy.version}</version> 
     <scope>provided</scope> 
     <exclusions> 
      <exclusion> 
       <groupId>commons-httpclient</groupId> 
       <artifactId>commons-httpclient</artifactId> 
      </exclusion> 
      <exclusion> 
       <groupId>javax.servlet</groupId> 
       <artifactId>servlet-api</artifactId> 
      </exclusion> 
      <exclusion> 
       <groupId>javax.xml.bind</groupId> 
       <artifactId>jaxb-api</artifactId> 
      </exclusion> 
      <exclusion> 
       <groupId>com.sun.xml.bind</groupId> 
       <artifactId>jaxb-impl</artifactId> 
      </exclusion> 
     </exclusions> 
    </dependency> 

    <dependency> 
     <groupId>org.jboss.resteasy</groupId> 
     <artifactId>resteasy-jaxb-provider</artifactId> 
     <version>${resteasy.version}</version> 
     <scope>provided</scope> 
     <exclusions> 
      <exclusion> 
       <groupId>javax.xml.bind</groupId> 
       <artifactId>jaxb-api</artifactId> 
      </exclusion> 
      <exclusion> 
       <groupId>com.sun.xml.bind</groupId> 
       <artifactId>jaxb-impl</artifactId> 
      </exclusion> 
      <exclusion> 
       <groupId>javax.xml.stream</groupId> 
       <artifactId>stax-api</artifactId> 
      </exclusion> 
     </exclusions> 
    </dependency> 

    <dependency> 
     <groupId>org.jboss.resteasy</groupId> 
     <artifactId>resteasy-jackson-provider</artifactId> 
     <version>${resteasy.version}</version> 
     <scope>provided</scope> 
     <exclusions> 
      <exclusion> 
       <groupId>javax.servlet</groupId> 
       <artifactId>servlet-api</artifactId> 
      </exclusion> 
     </exclusions> 
    </dependency> 

    <dependency> 
     <groupId>org.slf4j</groupId> 
     <artifactId>slf4j-api</artifactId> 
     <version>1.7.2</version> 
    </dependency> 
      <build> 
       <plugins> 
     <plugin> 
      <artifactId>maven-war-plugin</artifactId> 
      <version>2.1.1</version> 
      <configuration> 
       <!-- Java EE 6 doesn't require web.xml, Maven needs to catch up! --> 
       <failOnMissingWebXml>false</failOnMissingWebXml> 
       <archive> 
        <manifestEntries> 
         <Dependencies>org.jboss.resteasy.resteasy-jaxrs, 
          org.jboss.resteasy.resteasy-jaxb-provider, 
          org.jboss.resteasy.resteasy-jackson-provider, 
          org.apache.httpcomponents</Dependencies> 
         <version>${project.version}</version> 
        </manifestEntries> 
       </archive> 
      </configuration> 
     </plugin> 

請幫我。

回答

2

我在我的戰爭中使用jboss-deployment-structure.xml解決了這個問題,需要將它放在WEB_INF文件夾中。

<?xml version="1.0" encoding="UTF-8"?> 
<jboss-deployment-structure> 
    <deployment> 
    <dependencies> 
     <module name="org.jboss.resteasy.resteasy-jaxrs" services="export" export="true"/> 
     <module name="org.jboss.resteasy.resteasy-jaxb-provider" /> 
     <module name="org.jboss.resteasy.resteasy-jackson-provider" /> 
     <module name="org.codehaus.jackson.jackson-core-asl"/> 
     <module name="org.apache.httpcomponents" services="export" export="true"/> 
    </dependencies> 
    </deployment> 
</jboss-deployment-structure> 

有2種其他方式

1)添加的依賴性在META-INF文件,如下

Dependencies: org.jboss.resteasy.resteasy-jaxrs export services,org.jboss.resteasy.resteasy-jaxb-provider, org.jboss.resteasy.resteasyjackson-provider,org.apache.httpcomponents export services 

2)聲明爲在配置文件的domain.xml /獨立全局模塊.xml

<subsystem xmlns="urn:jboss:domain:ee:1.1"> 
<global-modules> 
<module name="org.jboss.resteasy.resteasy-jaxrs" slot="main" /> 
<module name="org.jboss.resteasy.resteasy-jaxb-provider" slot="main" /> 
<module name="org.jboss.resteasy.resteasy-jackson-provider" slot="main" /> 
<module name="org.apache.httpcomponents" slot="main" /> 
<module name="org.codehaus.jackson.jackson-core-asl" slot="main" /> 
</global-modules> 
相關問題