java找不到应用程序_Tyrus – 简单的java应用程序 – 找不到实现类

博主在尝试使用Java和Tyrus进行WebSocket应用开发时遇到了找不到实现类的问题。在服务器端和客户端的配置代码展示后,详细描述了错误信息。错误发生在调用`ContainerProvider.getWebSocketContainer()`时。服务器部署在GlassFish 4.0上,博主寻求解决方案。
摘要由CSDN通过智能技术生成

我正在开发简单的应用程序来帮助我学习

Java中的WebSocket和Tyrus概念.这是我的服务器端(服务器端点)和我的pom.xml以及我的客户端和pom.xml:

服务器端

@ServerEndpoint(value="/websocket/{client-id}")

public class MyServerEndpoint {

private static final LinkedList clients = new LinkedList();

@OnOpen

public void onOpen(Session session) {

clients.add(session);

}

@OnMessage

public void onMessage(String message,@PathParam("client-id") String clientId) {

for (Session client : clients) {

try {

client.getBasicRemote().sendObject(clientId+": "+message);

} catch (IOException e) {

e.printStackTrace();

} catch (EncodeException e) {

e.printStackTrace();

}

}

}

@OnClose

public void onClose(Session peer) {

clients.remove(peer);

}

}

的pom.xml

4.0.0

TyrusJacpFXServer

TyrusJacpFXServer

0.0.1-SNAPSHOT

war

javax.websocket

javax.websocket-api

compile

1.0

src

maven-compiler-plugin

3.1

1.7

1.7

maven-war-plugin

2.4

WebContent

false

客户端

MyClient.java

@ClientEndpoint

public class MyClient {

@OnOpen

public void onOpen(Session session) {

System.out.println("Connected to endpoint: " + session.getBasicRemote());

try {

session.getBasicRemote().sendText("Hello");

} catch (IOException ex) {

}

}

@OnMessage

public void onMessage(String message) {

System.out.println(message);

}

@OnError

public void onError(Throwable t) {

t.printStackTrace();

}

}

App.java

public class App {

public Session session;

protected void start()

{

WebSocketContainer container = ContainerProvider.getWebSocketContainer();

String uri = "ws://localhost:8080/TyrusJacpFXClient/websocket/desktop-client";

System.out.println("Connecting to " + uri);

try {

session = container.connectToServer(MyClient.class, URI.create(uri));

} catch (DeploymentException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

}

}

public static void main(String args[]){

App client = new App();

client.start();

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

String input = "";

try {

do{

input = br.readLine();

if(!input.equals("exit"))

client.session.getBasicRemote().sendText(input);

}while(!input.equals("exit"));

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}

的pom.xml

4.0.0

TyrusJacpFXClient

TyrusJacpFXClient

0.0.1-SNAPSHOT

javax.websocket

javax.websocket-api

compile

1.0

org.glassfish.tyrus

tyrus-client

1.8.3

org.glassfish.tyrus

tyrus-container-grizzly

1.1

src

maven-compiler-plugin

3.1

1.8

1.8

我收到此错误:

Exception in thread "main" java.lang.RuntimeException: Could not find an implementation class.

at javax.websocket.ContainerProvider.getWebSocketContainer(ContainerProvider.java:73)

at org.hwc.App.start(App.java:25)

at org.hwc.App.main(App.java:40)

有人可以帮我看看问题吗?服务器在GlassFish 4.0中运行

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值