3

我有一个 RestEasyClient 初始化如下并使用 Jboss AS 7.1 resteasy 模块

@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>

请帮助我。

4

1 回答 1

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/standalone.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>
于 2013-03-14T20:40:33.543 回答