gpt4 book ai didi

java - 无法加载容器提供程序类 : org. glassfish.tyrus.container.grizzly.GrizzlyEngine

转载 作者:行者123 更新时间:2023-11-30 08:43:38 26 4
gpt4 key购买 nike

我是 WebSockets 的新手。为了开始学习,我关注了this教程 。并简单地复制 ClientEndpointServerEndpoint 并使用 tyrus 部署服务器。

但是当我尝试运行服务器时它会抛出这个错误:

Failed to load container provider class: org.glassfish.tyrus.container.grizzly.GrizzlyEngine

这是部署代码(我已经注释掉我出错的行):

import java.io.BufferedReader;
import java.io.InputStreamReader;

import org.glassfish.tyrus.server.Server;

public class WebSocketServer {

public static void main(String[] args) {
runServer();
}

public static void runServer() {

Server server = new Server("localhost", 8000, "/websockets", WordgameServerEndpoint.class);

try {
server.start(); //i get the error on this line
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Please press a key to stop the server.");
reader.readLine();
} catch (Exception e) {
System.out.println(e.getMessage());
} finally {
server.stop();
}
}
}

这是服务器代码:

import java.io.IOException;
import java.util.logging.Logger;

import javax.websocket.CloseReason;
import javax.websocket.OnClose;
import javax.websocket.OnMessage;
import javax.websocket.OnOpen;
import javax.websocket.Session;
import javax.websocket.CloseReason.CloseCodes;
import javax.websocket.server.ServerEndpoint;

@ServerEndpoint(value = "/game")
public class WordgameServerEndpoint {

private Logger logger = Logger.getLogger(this.getClass().getName());

@OnOpen
public void onOpen(Session session) {
logger.info("Connected ... " + session.getId());
}

@OnMessage
public String onMessage(String message, Session session) {
switch (message) {
case "quit":
try {
session.close(new CloseReason(CloseCodes.NORMAL_CLOSURE, "Game ended"));
} catch (IOException e) {
throw new RuntimeException(e);
}
break;
}
return message;
}

@OnClose
public void onClose(Session session, CloseReason closeReason) {
logger.info(String.format("Session %s closed because of %s", session.getId(), closeReason));
}
}

我会很感激任何帮助:)

最佳答案

这似乎是一个依赖问题,

如果你是maven用户:

<dependencies>
<dependency>
<groupId>javax.websocket</groupId>
<artifactId>javax.websocket-api</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.glassfish.tyrus</groupId>
<artifactId>tyrus-server</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.tyrus</groupId>
<artifactId>tyrus-client</artifactId>
<version>1.1</version>
</dependency>

<dependency>
<groupId>org.glassfish.tyrus</groupId>
<artifactId>tyrus-container-grizzly</artifactId>
<version>1.1</version>
</dependency>

<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.5</version>
</dependency>
</dependencies>

或加载以下 jar :

  • grizzly-framework-2.3.3.jar
  • grizzly-http-2.3.3.jar
  • grizzly-http-server-2.3.3.jar
  • grizzly-rcm-2.3.3.jar
  • javax.websocket-api-1.0.jar
  • tyrus-client-1.1.jar
  • tyrus-container-grizzly-1.1.jar
  • tyrus-core-1.1.jar
  • tyrus-server-1.1.jar
  • tyrus-spi-1.1.jar
  • tyrus-websocket-core-1.1.jar

请记住客户端和服务器实现的这些依赖关系。

关于java - 无法加载容器提供程序类 : org. glassfish.tyrus.container.grizzly.GrizzlyEngine,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34140885/

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