Java WebSocket Client Standalone NoClassDefFoundError by ContainerProvider

I'm new to Java, but I have to use it to do a small WebSocket related project.

So, I installed JDK 1.8.0 and NetBeans 8.1 on my CentOS 7 in a VirtualBox.

I added the tyrus-standalone-client-jdk 1.12 plug-in in the pom.xml to make the standalone Websocket client, and it built fine. However, I ran into the error below:

[<a href="/cdn-cgi/l/email-protection" data-cfemail="1e6c71716a5e7d7b6a29">[email protected]</a> ~]# java -jar "/root/NetBeansProjects/Switchclient/target/Switchclient-1.0-SNAPSHOT.jar"

Exception in thread "main" java.lang.NoClassDefFoundError: javax/websocket/ContainerProvider
    at org.sample.switchclient.Switchclient.main(
Caused by: java.lang.ClassNotFoundException: javax.websocket.ContainerProvider
    at java.lang.ClassLoader.loadClass(
    at sun.misc.Launcher$AppClassLoader.loadClass(
    at java.lang.ClassLoader.loadClass(
    ... 1 more

[<a href="/cdn-cgi/l/email-protection" data-cfemail="94e6fbfbe0d4f7f1e0a3">[email protected]</a> ~]# java -version
java version "1.8.0_65"
Java(TM) SE Runtime Environment (build 1.8.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.65-b01, mixed mode)

I did a bit more searching and found that the "fully qualified classname of the container implementation of ContainerProvider must be listed in the META-INF/services/javax.websocket.ContainerProvider file in the implementation JAR file" for the ServiceLoader API according to Oracle documentation. So, I added the serviceloader-maven-plugin to the pom.xml. The result was that it did generate the META-INF/services/javax.websocket.ContainerProvider file, but without any content, and the runtime error continued to persist. I tried to modify the contents bellow manually and re-pack it into a JAR but it did not worked:

I've attached the Java file and the pom.xml . I've worked for hours and haven't a clue what the issue is, so any response to this thread will be appreciated.

Thank you very much.

===========LIST1: pom.xml===========

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="" xmlns:xsi="" xsi:schemaLocation="">






package org.sample.switchclient;

import javax.websocket.ClientEndpoint;
import javax.websocket.ContainerProvider;
import javax.websocket.OnMessage;
import javax.websocket.Session;
import javax.websocket.WebSocketContainer;

public class Switchclient {
    public void onRemoteMessage (String message) {
        System.out.println("Received msg: "+message);

    public static void main(String[] args) {
        WebSocketContainer container = null;
        Session session = null;
            container = ContainerProvider.getWebSocketContainer();
            session = container.connectToServer (Switchclient.class, URI.create("ws://localhost:8080/Switchserver/"));
        }catch (Exception e) {

Basically, Tyrus requires Java EE . It's the reason you have to list a lot of dependencies in pom.xml . If you use Java SE and want to keep your project small, use another different WebSocket client library that depends on only Java SE. For example, nv-websocket-client (mine).

Just add the following dependency to pom.xml ,


then try:


public class Switchclient
    public static void main(String[] args) throws Exception
        WebSocket websocket = new WebSocketFactory()
            .addListener(new WebSocketAdapter() {
                public void onTextMessage(WebSocket ws, String message) {
                    System.out.println("Received msg: " + message);

        // Don't forget to call disconnect() after use.
        // websocket.disconnect();