Solved NoClassDefFoundError when trying to use Kryonet

Discussion in 'Plugin Development' started by Assist, Sep 11, 2014.

Thread Status:
Not open for further replies.
  1. I've tried implementing the Kryonet networking library to my project, however I always get NoClassDefFoundError when the class is loaded. I know why and when the error should be thrown, but I cannot seem to fix it.

    I've tried adding the Kryonet jar as an external jar and a user library (not both at the same time, of course), and have modified the Order and Export in Eclipse to load Kryonet first.
    Show Spoiler
    [​IMG]

    Perhaps I'm doing something wrong? I haven't been coding for a while so I'm a bit rusty. Here is the relevant code:
    Code:java
    1. public void onEnable() {
    2. Thread serverThread = new IServer();
    3. serverThread.start();
    4. }

    Code:java
    1. import java.io.IOException;
    2.  
    3. import me.jhaz.bukkitbuddy.net.Network.Packet;
    4. import me.jhaz.bukkitbuddy.server.net.packet.PacketHandler;
    5.  
    6. import org.bukkit.Bukkit;
    7.  
    8. import com.esotericsoftware.kryonet.Connection;
    9. import com.esotericsoftware.kryonet.Listener;
    10. import com.esotericsoftware.kryonet.Server;
    11.  
    12. public class IServer extends Thread {
    13.  
    14. @Override
    15. public void run() {
    16. try {
    17. runServer();
    18. } catch (IOException e) {
    19. e.printStackTrace();
    20. return;
    21. }
    22. }
    23.  
    24. Server server;
    25.  
    26. private void runServer() throws IOException {
    27. server = new Server() {
    28. protected Connection newConnection() {
    29. return new MiddlemanConnection();
    30. }
    31. };
    32.  
    33. Network.register(server);
    34.  
    35. server.addListener(new Listener() {
    36. public void connected(Connection c) {
    37. Bukkit.getLogger().info("Middleman connected: " + c.getRemoteAddressTCP());
    38. }
    39.  
    40. public void received(Connection c, Object object) {
    41. if (object instanceof Packet) {
    42. Packet packet = (Packet) object;
    43. PacketHandler.handlePacket(c, packet);
    44. return;
    45. }
    46. }
    47.  
    48. public void disconnected(Connection c) {
    49. Bukkit.getLogger().info("Middleman disconnected");
    50. }
    51. });
    52.  
    53. server.bind(Network.port);
    54. server.start();
    55.  
    56. Bukkit.getLogger().info("Waiting for middleman...");
    57. }
    58.  
    59. static class MiddlemanConnection extends Connection {}
    60. }

    Thanks in advance.

    Edit: Sorry, the formatting messed up when I edited my post earlier.
     
  2. Offline

    fireblast709

    Assist Your IDE might know about the jar, but the server doesn't. You need to add the jar to the Class-Path in such a way that it can be found from the server root. For example:
    • Class-Path has "../lib/kryonet-2.21-all.jar"
    • <server root>/lib/ should have a the jar, named kryonet-2.21-all.jar
     
    Assist likes this.
  3. Assist First step is to check your jar contents to make sure that the required packages have been exported.
     
    Assist likes this.
  4. fireblast709
    That must be it, I knew I forgot something!

    AdamQpzm
    I would have, but I'm not sure how. Usually I just open the jar with WinRAR, however I don't have it on this computer.
     
Thread Status:
Not open for further replies.

Share This Page