2

I have two different Modules: MultiRealm and SurvivalRealm. MultiRealm provides an abstract class (LoadedRealm) which the class SurvivalRealm (in the Module SurvivalRealm) extends. Now, MultiRealm tries to load the SurvivalRealm class from the jar. But when trying to load, i get the Following error: java.lang.NoClassDefFoundError: net/lightbluefoxlabs/dev/multirealm/core/multirealmcore/Realms/LoadedRealm where net/lightbluefoxlabs/dev/multirealm/core/multirealmcore/Realms/LoadedRealm is the correct location of the LoadedRealm class. Here is the Stacktrace:

[23:03:52] [Thread-10/WARN]:    at java.lang.ClassLoader.defineClass1(Native Method)
[23:03:52] [Thread-10/WARN]:    at java.lang.ClassLoader.defineClass(Unknown Source)
[23:03:52] [Thread-10/WARN]:    at java.security.SecureClassLoader.defineClass(Unknown Source)
[23:03:52] [Thread-10/WARN]:    at java.net.URLClassLoader.defineClass(Unknown Source)
[23:03:52] [Thread-10/WARN]:    at java.net.URLClassLoader.access$100(Unknown Source)
[23:03:52] [Thread-10/WARN]:    at java.net.URLClassLoader$1.run(Unknown Source)
[23:03:52] [Thread-10/WARN]:    at java.net.URLClassLoader$1.run(Unknown Source)
[23:03:52] [Thread-10/WARN]:    at java.security.AccessController.doPrivileged(Native Method)
[23:03:52] [Thread-10/WARN]:    at java.net.URLClassLoader.findClass(Unknown Source)
[23:03:52] [Thread-10/WARN]:    at java.lang.ClassLoader.loadClass(Unknown Source)
[23:03:52] [Thread-10/WARN]:    at java.lang.ClassLoader.loadClass(Unknown Source)
[23:03:52] [Thread-10/WARN]:    at net.lightbluefoxlabs.dev.multirealm.core.multirealmcore.Realms.LoadedRealm.RealmFactory(LoadedRealm.java:54)
[23:03:52] [Thread-10/WARN]:    at net.lightbluefoxlabs.dev.multirealm.core.multirealmcore.Realms.LoadedRealm.RealmFactory(LoadedRealm.java:20)
[23:03:52] [Thread-10/WARN]:    at net.lightbluefoxlabs.dev.multirealm.core.multirealmcore.Realms.RealmManager.Initialize(RealmManager.java:22)
[23:03:52] [Thread-10/WARN]:    at net.lightbluefoxlabs.dev.multirealm.core.multirealmcore.Realms.RealmManager.lambda$InitializeAsync$0(RealmManager.java:39)
[23:03:52] [Thread-10/WARN]:    at java.lang.Thread.run(Unknown Source)
[23:03:52] [Thread-10/WARN]: Caused by: java.lang.ClassNotFoundException: net.lightbluefoxlabs.dev.multirealm.core.multirealmcore.Realms.LoadedRealm
[23:03:52] [Thread-10/WARN]:    at java.net.URLClassLoader.findClass(Unknown Source)
[23:03:52] [Thread-10/WARN]:    at java.lang.ClassLoader.loadClass(Unknown Source)
[23:03:52] [Thread-10/WARN]:    at java.lang.ClassLoader.loadClass(Unknown Source)
[23:03:52] [Thread-10/WARN]:    ... 16 more

Here is the SurvivalRealm class:

import net.lightbluefoxlabs.dev.multirealm.core.multirealmcore.Realms.LoadedRealm;
import net.lightbluefoxlabs.dev.multirealm.core.multirealmcore.Realms.Worlds.RealmWorld;

public class SurvivalRealm extends LoadedRealm {

    public SurvivalRealm(String RealmPath) {
        super(RealmPath);
        Load();
    }

    @Override
    public void Load() {
        //LoadStuff
    }

    @Override
    public void Unload() {

    }
}

... and this static function in LoadedRealm tries to import this class:

public static LoadedRealm RealmFactory(String jarPath, String RealmPath)  throws RealmLoadException{
        try {
            File file = new File(jarPath);
            URLClassLoader c = new URLClassLoader(new URL[]{file.getAbsoluteFile().toURI().toURL()});
            Class<?> realmClass = c.loadClass(RealmClass);
            return (LoadedRealm)(realmClass.getDeclaredConstructor(String.class).newInstance(RealmPath));
        }catch (Exception e){
            throw new RealmLoadException(e);
        }
    }

Here is a picture of the Structure: enter image description here

The MultiRealm Module does not import/"Know about" (excuse my terminology) the SurvivalRealm module, only the other way around.

Am I just trying to achieve something impossible? If you need the .iml file, just ask. Any help would be really apreciated, I have been trying to fix this issue for basically the whole day now. Thanks for reading through this beginner issue.

Vladislav Varslavans
  • 2,775
  • 4
  • 18
  • 33
Jakob Tinhofer
  • 313
  • 3
  • 16

1 Answers1

1

You should try using your pom files from maven for achieve your goal. A multi-module project is defined by a parent POM referencing one or more submodules.

Argotto
  • 50
  • 7
  • Thank you for your answer. Is there a way to make this independent of knowing the name of the submodules? I want to be able to create new modules without having to modify the parent – Jakob Tinhofer Dec 16 '20 at 11:23
  • The most logical thing is that you have to reference them in the parent POM, inside the tags. A guide to get started: https://maven.apache.org/guides/mini/guide-multiple-modules.html – Argotto Dec 16 '20 at 13:36
  • Sounds reasonable. But how does for example the minecraft bukkit api implement that (i know, great example..). In order to develop a plugin, you extend a class that is in the same jar as the server itsself, then put it in the plugin folder. There is no need to modify the jar itsself or anything the like – Jakob Tinhofer Dec 16 '20 at 21:16