当前位置: 首页 > 工具软件 > Tyrus > 使用案例 >

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

麻宜春
2023-12-01

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

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中运行

 类似资料: