Question Minecraft Plugin OkHttp3 java.lang.ClassNotFoundException: okhttp3.OkHttpClient

salm2s

Reputable
Jul 21, 2017
262
5
4,815
6
Hi there,

I am trying to make a simple Minecraft plugin using JetBrains Intellij. I am trying to use OkHttp3 to make a get request just as a test to see if it would work:
Code:
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import okhttp3.*;

public class HelloCommand implements CommandExecutor {
    private Main plugin;

    public HelloCommand(Main plugin) {
        this.plugin = plugin;
        plugin.getCommand("hello").setExecutor(this);
    }

    @Override
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
        if (!(sender instanceof Player)) {
            sender.sendMessage("You're not a player m8");
            return true;
        }
        Player player = (Player) sender;
        player.sendMessage("Hello there " + player.getDisplayName());

        OkHttpClient client = new OkHttpClient();

        Request r = new Request.Builder()
                .url("https://google.com")
                .build();

        System.out.println(r.body());

        return false;
    }
}
However, whenever I do the command /hello in my minecraft server, I am always greeted with this weird error:
Code:
Caused by: java.lang.NoClassDefFoundError: okhttp3/OkHttpClient
	at nugetzrul3.mc.tipbot.commands.HelloCommand.onCommand(HelloCommand.java:29) ~[?:?]
	at org.bukkit.command.PluginCommand.execute(PluginCommand.java:45) ~[spigot-1.16.3.jar:git-Spigot-2740d5a-890130b]
	... 18 more
Caused by: java.lang.ClassNotFoundException: okhttp3.OkHttpClient
	at java.net.URLClassLoader.findClass(Unknown Source) ~[?:?]
	at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:167) ~[spigot-1.16.3.jar:git-Spigot-2740d5a-890130b]
	at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:96) ~[spigot-1.16.3.jar:git-Spigot-2740d5a-890130b]
	at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:?]
	at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:?]
	at nugetzrul3.mc.tipbot.commands.HelloCommand.onCommand(HelloCommand.java:29) ~[?:?]
	at org.bukkit.command.PluginCommand.execute(PluginCommand.java:45) ~[spigot-1.16.3.jar:git-Spigot-2740d5a-890130b]
	... 18 more
I am very confused as to why it says that the class is not found even though I have installed OkHttp3 through maven.
Am I missing something when I create the .jar artifact?

Thanks,
salm2s
 

ASK THE COMMUNITY

TRENDING THREADS