Java Undertow Dependency Issue

1k Views Asked by At

I'm trying to get Undertow working in a Java App but I'm having some issues with dependencies. Everything is compiling ok but every time I try to run I am getting the following error.

Exception in thread "main" java.lang.NoClassDefFoundError: org/xnio/ChannelListener

I'm not using maven but I downloaded the following Undertow jars from the link off of the Undertow site.

undertow-core-2.2.13.Final.jar
undertow-servlet-2.2.13.Final.jar
undertow-websockets-jsr-2.2.13.Final.jar

The code is pretty much the same as the example given on the Undertow site and I can't find very much mention of the specific dependencies. I'm sure I'm missing something

import java.util.*;
import java.io.*;

import io.undertow.*;
import io.undertow.server.*;
import io.undertow.util.*;

public class TestingUndertow {

    public static void main(String[] args) {

        Undertow server = (
            Undertow
            .builder()
            .addHttpListener(31, "0.0.0.0")
            .setHandler(new HttpHandler() {
                public void handleRequest(final HttpServerExchange exchange) throws Exception {
                    exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "text/plain");
                    exchange.getResponseSender().send("Nothing");
                }
            })
            .build()
        );

        server.start();

    }

}
1

There are 1 best solutions below

2
TheLovelySausage On

It turns out I was missing many dependencies, these were all needed for it to work

jboss-logging-3.4.2.Final.jar
jboss-threads-3.4.2.Final.jar
undertow-core-2.2.12.Final.jar
undertow-servlet-2.2.12.Final.jar
wildfly-client-config-1.0.1.Final.jar
wildfly-common-1.5.4.Final.jar
xnio-api-3.8.4.Final.jar
xnio-nio-3.8.4.Final.jar

If this can help anyone else who has dependency issues like me, I found this site really helpful https://javalibs.com/

You can search for a module and it will let you know all of the dependencies for that module so you can know to download them too (or just use maven really)