gpt4 book ai didi

jboss7.x - Jboss AS 7.1 中的 Resteasy 客户端抛出 java.lang.ClassNotFoundException : com. sun.ws.rs.ext.RuntimeDelegateImpl

转载 作者:行者123 更新时间:2023-12-02 02:05:33 25 4
gpt4 key购买 nike

我有一个 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>

请帮助我。

最佳答案

我通过在我的 war 中使用 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>

关于jboss7.x - Jboss AS 7.1 中的 Resteasy 客户端抛出 java.lang.ClassNotFoundException : com. sun.ws.rs.ext.RuntimeDelegateImpl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15235531/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com