TooTallNate / Java-WebSocket

A barebones WebSocket client and server implementation written in 100% Java.
http://tootallnate.github.io/Java-WebSocket
MIT License
10.45k stars 2.57k forks source link

How to run chat example using Maven or Gradle? #946

Open PhilipRoman opened 4 years ago

PhilipRoman commented 4 years ago

I was looking for an alternative to the chat server instructions (https://tootallnate.github.io/Java-WebSocket/) mentioned in #937.

Apparently, running the examples used to be as simple as this:

ant
java -cp build/examples:dist/java_websocket.jar ChatServer
java -cp build/examples:dist/java_websocket.jar ChatClient

When I tried building it now using Maven or Gradle, the classes under src/main/example/ weren't being compiled so I had to manually javac them and then download SLF4J dependency jars.

Maybe there should be a simple build task so you can do, for example gradle example or mvn example to run the examples.

marci4 commented 4 years ago

I like the idea with mvn example! :)

dota17 commented 4 years ago

1、 update pom.xml line 166:

src/main

After pom.xml was changed, directly mvn clean install , it would fail with follow message:
[ERROR] Failed to execute goal biz.aQute.bnd:bnd-maven-plugin:4.3.1:bnd-process (default) on project Java-WebSocket: The default package '.' is not permitted by the Import-Package syntax.

2、 add package to the java of example : mvn clean install , it was successful. And the classes ware in the dir of example: mvnbuild_20200815150557 Ex : https://github.com/dota17/Java-WebSocket/pull/15 This is just an example how I use it, I hope it can help you.

3、 Add the dependency of slf4j-api-1.7.25 in the libs: /c/code/local/Java-WebSocket/libs abc@desktop MINGW64 /c/code/local/Java-WebSocket/libs (exampleBuild) $ ls -lrt total 60 -rw-r--r-- 1 abc 197121 41203 2月 11 2020 slf4j-api-1.7.25.jar -rw-r--r-- 1 abc 197121 15257 6月 28 16:11 slf4j-simple-1.7.25.jar

4、 We can run the example with java: cd target/classes/

$ /c/code/local/Java-WebSocket/target/classes (exampleBuild) java -Djava.ext.dirs=/c/code/local/Java-WebSocket/libs example.ChatServer

5、The return result : ChatServer started on port: 8887 Server started!