Solved Jetty websocket help needed.

Discussion in 'Plugin Development' started by G_4s, Nov 23, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    G_4s

    Hey guys,

    i'm trying to make a plugin where i need to use the jetty websocket i can run my jetty (server) code for the websocket in an separet program and it works perfect but if i go and try to implement it in my plugin i get NoClassDefFoundError: org/eclipse/jetty/server/Connector errors if i run the plugin in the server.

    i'm new in this area can anybody help me out with this ?

    full error:
    Code:
    [12:22:33 ERROR]: Could not load 'plugins\WebsocketPlugin-1.0-SNAPSHOT.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidPluginException: java.lang.NoClassDefFoundError: org/eclipse/jetty/server/Connector
            at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:135) ~[spigot.jar:git-Spigot-c5146ba
    -01930e2]
            at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:329) ~[spigot.jar:git-Spigot-c5146b
    a-01930e2]
            at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:251) [spigot.jar:git-Spigot-c5146b
    a-01930e2]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.loadPlugins(CraftServer.java:291) [spigot.jar:git-Spigot-c5146ba-0
    1930e2]
            at net.minecraft.server.v1_8_R3.DedicatedServer.init(DedicatedServer.java:198) [spigot.jar:git-Spigot-c5146ba-01
    930e2]
            at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:528) [spigot.jar:git-Spigot-c5146ba-019
    30e2]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_60]
    Caused by: java.lang.NoClassDefFoundError: org/eclipse/jetty/server/Connector
            at java.lang.Class.forName0(Native Method) ~[?:1.8.0_60]
            at java.lang.Class.forName(Unknown Source) ~[?:1.8.0_60]
            at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:64) ~[spigot.jar:git-Spigot-c5146ba-01
    930e2]
            at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:131) ~[spigot.jar:git-Spigot-c5146ba
    -01930e2]
            ... 6 more
    Caused by: java.lang.ClassNotFoundException: org.eclipse.jetty.server.Connector
            at java.net.URLClassLoader.findClass(Unknown Source) ~[?:1.8.0_60]
            at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:101) ~[spigot.jar:git-Spigot-c5146b
    a-01930e2]
            at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:86) ~[spigot.jar:git-Spigot-c5146ba
    -01930e2]
            at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.8.0_60]
            at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.8.0_60]
            at java.lang.Class.forName0(Native Method) ~[?:1.8.0_60]
            at java.lang.Class.forName(Unknown Source) ~[?:1.8.0_60]
            at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:64) ~[spigot.jar:git-Spigot-c5146ba-01
    930e2]
            at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:131) ~[spigot.jar:git-Spigot-c5146ba
    -01930e2]
            ... 6 more
    source code:
    Code:
    public class WebsocketPlugin {
        Server server;
        org.bukkit.Server bukkitserver;
        public WebsocketPlugin(org.bukkit.Server bukkitserver) {
            server = new Server();
            this.bukkitserver = bukkitserver;
            ServerConnector connector = new ServerConnector(server);
            connector.setPort(8080);
            server.addConnector(connector);
           
            ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
            context.setContextPath("/");
            server.setHandler(context);
    
            try {
    
                javax.websocket.server.ServerContainer wscontainer = WebSocketServerContainerInitializer.configureContext(context);
    
                wscontainer.addEndpoint(EventSocket.class);
    
                server.start();
                server.dump(System.err);
                server.join();
            }
            catch (Throwable t) {
                t.printStackTrace(System.err);
            }
        }
       
        public void stop() {
            try {
                server.stop();
            } catch(Exception x) {
                bukkitserver.getLogger().severe(x.getMessage());
            }
        }
    }
     
  2. Offline

    Scimiguy

    Looks like you don't have your Jetty dependency available at runtime
     
  3. Offline

    G_4s

    Yeah i kbow but how do i fix this because i tried to compile it with tje dependencies and that did not do anything else :/
     
  4. Offline

    FabeGabeMC

    @G_4s
    Instead of adding it with the 'Add External Jar feature', make a new folder in your project (call it libs if you want), then go to your build settings and click "Add Library". Finally, add your jar from the libs folder.
     
  5. Offline

    G_4s

    I will try that right away

    but i added it in the pom dependencies exually ? and how do i do that because this is new terain for me :D

    Well I fixed it but out of school we learned working with netbeans i hated it but just did it in eclipse and it works fine :D thx all :D

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Nov 23, 2015
Thread Status:
Not open for further replies.

Share This Page