问题
I have a RestEasyClient which initialize as follows and uses the Jboss AS 7.1 resteasy module
@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);
}
This throws following error during server startup
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)
My pom.xml is as follows
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>
Please help me in this.
回答1:
I solved the issue by using jboss-deployment-structure.xml in my war, which needs to be placed in WEB_INF folder.
<?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>
There are 2 other ways
1) Adding dependency in META-INF file as below
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) Declare them as global module in the configuration file 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>
来源:https://stackoverflow.com/questions/15235531/resteasy-client-in-jboss-as-7-1-throws-java-lang-classnotfoundexception-com-sun