我有一个ejb项目(使用maven构建),我正在尝试通过eclipse ui部署在jboss 7.1 EAP应用服务器中。我可以成功依赖于websocket实现的依赖关系来构建jar(mvn全新安装),以及在启动时运行单例bean(使用@Startup进行注释并将println放入构造函数中)。但是,当我使用使用Maven依赖项的代码启动服务器时,它将引发NoClassDefFoundError。有什么想法吗?
pom.xml源文件
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.connor.wstest</groupId>
<artifactId>WebSocketEJB</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>ejb</packaging>
<dependencies>
<!-- official socket.io java implementation (ported from original javascript) -->
<dependency>
<groupId>io.socket</groupId>
<artifactId>socket.io-client</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>ejbModule</sourceDirectory>
<resources>
<resource>
<directory>ejbModule</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-ejb-plugin</artifactId>
<version>2.5</version>
<configuration>
<ejbVersion>3.1</ejbVersion>
</configuration>
</plugin>
</plugins>
</build>
</project>
错误堆栈跟踪(仅在将ejb部署到jboss应用服务器并具有导入了代码引用的库时发生)
1:13,929 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 62) MSC000001: Failed to start service jboss.deployment.unit."CryptoWs.jar".component.StartupOne.START: org.jboss.msc.service.StartException in service jboss.deployment.unit."CryptoWs.jar".component.StartupOne.START: java.lang.IllegalStateException: WFLYEE0042: Failed to construct component instance
at org.jboss.as.ee.component.ComponentStartService$1.run(ComponentStartService.java:57)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
at org.jboss.threads.JBossThread.run(JBossThread.java:320)
Caused by: java.lang.IllegalStateException: WFLYEE0042: Failed to construct component instance
at org.jboss.as.ee.component.BasicComponent.constructComponentInstance(BasicComponent.java:163)
at org.jboss.as.ee.component.BasicComponent.constructComponentInstance(BasicComponent.java:134)
at org.jboss.as.ee.component.BasicComponent.createInstance(BasicComponent.java:88)
at org.jboss.as.ejb3.component.singleton.SingletonComponent.getComponentInstance(SingletonComponent.java:124)
at org.jboss.as.ejb3.component.singleton.SingletonComponent.start(SingletonComponent.java:138)
at org.jboss.as.ee.component.ComponentStartService$1.run(ComponentStartService.java:54)
... 6 more
Caused by: javax.enterprise.inject.CreationException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at java.lang.Class.newInstance(Class.java:442)
at org.jboss.weld.security.NewInstanceAction.run(NewInstanceAction.java:33)
at java.security.AccessController.doPrivileged(Native Method)
at org.jboss.weld.injection.Exceptions.rethrowException(Exceptions.java:40)
at org.jboss.weld.injection.Exceptions.rethrowException(Exceptions.java:50)
at org.jboss.weld.injection.Exceptions.rethrowException(Exceptions.java:90)
at org.jboss.weld.injection.ConstructorInjectionPoint.newInstance(ConstructorInjectionPoint.java:127)
at org.jboss.weld.injection.ConstructorInjectionPoint$1.proceed(ConstructorInjectionPoint.java:101)
at org.jboss.as.weld.injection.WeldManagedReferenceFactory.create(WeldManagedReferenceFactory.java:51)
at org.jboss.as.ee.component.ComponentInstantiatorInterceptor.processInvocation(ComponentInstantiatorInterceptor.java:67)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
at org.jboss.as.weld.interceptors.Jsr299BindingsInterceptor.doLifecycleInterception(Jsr299BindingsInterceptor.java:122)
at org.jboss.as.weld.interceptors.Jsr299BindingsInterceptor.processInvocation(Jsr299BindingsInterceptor.java:113)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
at org.jboss.as.weld.injection.WeldConstructionStartInterceptor$1.aroundConstruct(WeldConstructionStartInterceptor.java:53)
at org.jboss.weld.injection.ConstructorInjectionPoint.invokeAroundConstructCallback(ConstructorInjectionPoint.java:109)
at org.jboss.weld.injection.ConstructorInjectionPoint.invokeAroundConstructCallbacks(ConstructorInjectionPoint.java:95)
at org.jboss.weld.injection.ConstructorInjectionPoint.newInstance(ConstructorInjectionPoint.java:78)
at org.jboss.weld.injection.producer.AbstractInstantiator.newInstance(AbstractInstantiator.java:28)
at org.jboss.weld.injection.producer.BasicInjectionTarget.produce(BasicInjectionTarget.java:112)
at org.jboss.weld.injection.producer.BeanInjectionTarget.produce(BeanInjectionTarget.java:180)
at org.jboss.weld.injection.producer.ejb.SessionBeanInjectionTarget.produce(SessionBeanInjectionTarget.java:126)
at org.jboss.as.weld.injection.WeldInjectionContext.produce(WeldInjectionContext.java:46)
at org.jboss.as.weld.injection.WeldConstructionStartInterceptor.processInvocation(WeldConstructionStartInterceptor.java:37)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:53)
at org.jboss.as.ee.component.AroundConstructInterceptorFactory$1.processInvocation(AroundConstructInterceptorFactory.java:26)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
at org.jboss.as.weld.injection.WeldInterceptorInjectionInterceptor.processInvocation(WeldInterceptorInjectionInterceptor.java:56)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
at org.jboss.as.weld.interceptors.Jsr299BindingsCreateInterceptor.processInvocation(Jsr299BindingsCreateInterceptor.java:105)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
at org.jboss.as.ee.component.NamespaceContextInterceptor.processInvocation(NamespaceContextInterceptor.java:50)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
at org.jboss.as.weld.injection.WeldInjectionContextInterceptor.processInvocation(WeldInjectionContextInterceptor.java:43)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
at org.jboss.as.ejb3.component.interceptors.CurrentInvocationContextInterceptor.processInvocation(CurrentInvocationContextInterceptor.java:41)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
at org.jboss.as.ee.concurrent.ConcurrentContextInterceptor.processInvocation(ConcurrentContextInterceptor.java:45)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
at org.jboss.invocation.ContextClassLoaderInterceptor.processInvocation(ContextClassLoaderInterceptor.java:60)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
at org.jboss.as.ejb3.component.singleton.StartupCountDownInterceptor.processInvocation(StartupCountDownInterceptor.java:25)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422)
at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:53)
at org.jboss.as.ee.component.BasicComponent.constructComponentInstance(BasicComponent.java:161)
... 11 more
Caused by: java.lang.NoClassDefFoundError: io/socket/client/IO
at com.connor.StartupOne.<init>(StartupOne.java:33)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.jboss.weld.injection.ConstructorInjectionPoint.newInstance(ConstructorInjectionPoint.java:119)
... 50 more
Caused by: java.lang.ClassNotFoundException: io.socket.client.IO from [Module "deployment.CryptoWs.jar" from Service Module Loader]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:198)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:412)
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:400)
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:116)
... 56 more
22:41:13,950 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("deploy") failed - address: ([("deployment" => "CryptoWs.jar")]) - failure description: {"WFLYCTL0080: Failed services" => {"jboss.deployment.unit.\"CryptoWs.jar\".component.StartupOne.START" => "java.lang.IllegalStateException: WFLYEE0042: Failed to construct component instance
Caused by: java.lang.IllegalStateException: WFLYEE0042: Failed to construct component instance
Caused by: javax.enterprise.inject.CreationException
Caused by: java.lang.NoClassDefFoundError: io/socket/client/IO
Caused by: java.lang.ClassNotFoundException: io.socket.client.IO from [Module \"deployment.CryptoWs.jar\" from Service Module Loader]"}}
22:41:14,013 INFO [org.jboss.as.server] (ServerService Thread Pool -- 37) WFLYSRV0010: Deployed "CryptoWs.jar" (runtime-name : "CryptoWs.jar")
22:41:14,013 INFO [org.jboss.as.controller] (Controller Boot Thread) WFLYCTL0183: Service status report
WFLYCTL0186: Services which failed to start: service jboss.deployment.unit."CryptoWs.jar".component.StartupOne.START: java.lang.IllegalStateException: WFLYEE0042: Failed to construct component instance
以下是引发异常的代码:
package com.connor;
import java.net.URISyntaxException;
import java.util.stream.Stream;
import javax.ejb.Asynchronous;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import io.socket.client.IO;
import io.socket.client.Socket;
/**
* Session Bean implementation class StartupOne
*/
@Singleton
@Asynchronous
@Startup
public class StartupOne {
/**
* Default constructor.
*/
public StartupOne() {
// TODO Auto-generated constructor stub
Socket socket;
System.out.println("***" + Thread.currentThread().getName());
try {
socket = IO.socket("wss://www.bitmex.com/realtime?subscribe=instrument"); //THIS LINE THROWS THE EXCEPTION!!!!!!
socket
.on(Socket.EVENT_CONNECT, args -> {
/*
Map<String, Object> eventArgs = new HashMap<>();
eventArgs.put("subs", Arrays.asList(subscriptions));
socket.emit("SubAdd", eventArgs);
*/
})
.on("m", args -> Stream.of(args).forEach(arg -> {
// Log the raw message for debug
System.out.println("Raw message: "+arg);
//CryptoCompareResponse response = CryptoCompareResponse.unpack((String) arg);
//if (response.getMessageType() == 5 && (response.getFlag() == 1 || response.getFlag() == 2)) {
// updatePricing(response);
//}
}))
.on(Socket.EVENT_DISCONNECT, args -> System.out.println("Received disconnect event"));
socket.connect();
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
答案 0 :(得分:1)
根异常是ClassNotFoundException
,它告诉您部署CryptoWs.jar
找不到类io.socket.client.IO
。那课在哪里?它在罐子socket.io-client-1.0.0.jar
中。但是在jboss的上下文中那个jar在哪里?答案是,不可用。现在您有不同的选择。
WebSocketEJB
创建战争档案。然后应将jar添加到战争档案的lib文件夹中。我建议您尝试使用选项1。