gpt4 book ai didi

java - JBoss 编译但启动时出现 NoClassDefFoundError

转载 作者:行者123 更新时间:2023-11-30 05:56:00 24 4
gpt4 key购买 nike

我有一个 ejb 项目(使用 maven 构建),我正在尝试在 jboss 7.1 EAP 应用程序服务器中部署(通过 eclipse ui)。我可以成功构建依赖于 websocket 实现的 jar(mvn clean install),以及在启动时运行单例 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();
}

}

}

最佳答案

根异常是ClassNotFoundException,它告诉您,您的部署CryptoWs.jar找不到类io.socket.client.IO.那么这个类在哪里呢?它位于 jar socket.io-client-1.0.0.jar 中。但是 jboss 上下文中那个 jar 放在哪里呢?答案是,不可用。现在您有不同的选择。

  1. 使用 WebSocketEJB 创建一个 war 存档。然后应该将该 jar 添加到 war 存档的 lib 文件夹中。
  2. 为socket.io-client创建一个jboss模块并让WebSocketEJB指向它。 ( list 条目)
  3. 创建一个 uber jar。

我建议您尝试使用选项 1。

关于java - JBoss 编译但启动时出现 NoClassDefFoundError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53183377/

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