Search code examples
javaintellij-ideajarmanifestminecraft

Reference to a jar lib results in ClassNotFoundException with IntelliJ


I am compiling a plugin for minecraft which basically play a song on login. Source code can be found here.

A plugin already exists and provides a media player with a tutorial which I followed MC_Jukebox, source code is here

My code use this external jar to do the job :

package com.iqbrod.excilysplugin;

import net.mcjukebox.plugin.bukkit.api.JukeboxAPI;
import net.mcjukebox.plugin.bukkit.api.ResourceType;
import net.mcjukebox.plugin.bukkit.api.models.Media;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;

public class LoginListener implements Listener {

    @EventHandler
    public void onPlayerJoin(PlayerJoinEvent event) {
        Media media = new Media(ResourceType.MUSIC, "https://od.lk/s/MTFfMjQ2ODM2NTRf/music1.mp3");
        JukeboxAPI.play(event.getPlayer(), media);
    }
}

This code is correct and should play a music on a PlayerJoinEvent. My problem comes from compilation to jar which contains:

com/* #Source code
lib/* #external Jars (MC_Jukebox)
plugin.yml #required by Minecraft Server
META-INF/MANIFEST.MF #details below

Source code com/* is basic Java and correct compared to existing plugins/code. Lib contains my library jar. plugin.yml is correct and works without the references to lib classes. MANIFEST.MF is

Manifest-Version: 1.0
Main-Class: EntryPoint
Class-Path: lib/

PROBLEM
Even with a reference to lib in Class-Path of MANIFEST running server & client results in

[13:26:27] [Server thread/ERROR]: Could not pass event PlayerJoinEvent to ExcilysPlugin v1.0 org.bukkit.event.EventException: null
(...)
Caused by: java.lang.NoClassDefFoundError: net/mcjukebox/plugin/bukkit/api/models/Media
(...)
Caused by: java.lang.ClassNotFoundException: net.mcjukebox.plugin.bukkit.api.models.Media

How can I reference the jar contained in my jar under the folder lib ?

I'm using Intellij to code and compile. I read this post and also tried to use "Extract Folder".
Both results in a ClassNotFoundException.


Solution

  • The jars reference in MANIFEST points to local directory (.minecraft/plugins/) and not source code one.

    To solve this: My external jars are in .minecraft/plugins/lib and not .minecraft/plugins/myplugin/lib.
    Another solution is to point these jars in MANIFEST.mf as

    ClassPath: myplugin/lib