我有两个不同的模块: MultiRealm
以及 SurvivalRealm
. 多领域提供了一个抽象类(loadedrealm),该类 SurvivalRealm
(在模块中) SurvivalRealm
)延伸。现在,multirealm尝试从jar加载survivalrealm类。但在尝试加载时,出现以下错误: java.lang.NoClassDefFoundError: net/lightbluefoxlabs/dev/multirealm/core/multirealmcore/Realms/LoadedRealm
哪里 net/lightbluefoxlabs/dev/multirealm/core/multirealmcore/Realms/LoadedRealm
是loadedrealm类的正确位置。下面是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
以下是survivalrealm类:
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() {
}
}
... loadedrealm中的静态函数尝试导入此类:
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);
}
}
以下是结构图:
multirealm模块不导入/“know about”(请原谅我的术语)survivalrealm模块,只是相反。
我只是想做些不可能的事吗?如果你需要.iml文件,尽管问。任何帮助都是非常感谢的,我已经试着解决这个问题基本上一整天了。感谢您阅读本期初级读物。
1条答案
按热度按时间suzh9iv81#
您应该尝试使用maven的pom文件来实现您的目标。多模块项目由引用一个或多个子模块的父pom定义。