1

我目前有一个具有多个依赖项(包含在 jar 中)和一个位于其他地方的单个依赖项的 maven 项目,该依赖项也被编译为 jar 文件。现在我正在尝试在我的项目中动态加载类,这样一个简单的类就可以工作:

public class test {
    static {
        System.out.println("SUCCESS!");
    }
}

但是一旦我的班级试图与我的项目互动,它就会说无法解决外部依赖关系。有没有办法在我编译时自动将项目的所有依赖项包含到我的类路径中?(我已经添加了project.jar)或者有没有其他方法可以编译它并执行这个类而没有这个问题?

编辑:它现在正在编译,因为我将 jar 手动添加到我的类路径中,但我现在遇到运行时异常

我的课:

import be.multicu.core.MultiCube;

public class Debug {

    public void debug() {
        System.out.println(MultiCube.getInstance().getCurrentServer().getOnlinePlayers());
    }
}

异常(注意:日志是反转的!):

java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_51]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[?:1.7.0_51]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.7.0_51]
at java.lang.reflect.Method.invoke(Method.java:606) ~[?:1.7.0_51]
at be.multicu.core.util.Debugger.debugFromPastebin(Debugger.java:54) [MultiCubeCore.jar:?]
at be.multicu.core.command.commands.debug.run(debug.java:68) [MultiCubeCore.jar:?]
at be.multicu.core.command.BaseCommand.onCommand(BaseCommand.java:55) [MultiCubeCore.jar:?]
at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) [craftcubbit.jar:git-Spigot-1.7.2-R0.3-178-g45eab08]
at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:180) [craftcubbit.jar:git-Spigot-1.7.2-R0.3-178-g45eab08]
at org.bukkit.craftbukkit.v1_7_R3.CraftServer.dispatchCommand(CraftServer.java:724) [craftcubbit.jar:git-Spigot-1.7.2-R0.3-178-g45eab08]
at net.minecraft.server.v1_7_R3.PlayerConnection.handleCommand(PlayerConnection.java:985) [craftcubbit.jar:git-Spigot-1.7.2-R0.3-178-g45eab08]
at net.minecraft.server.v1_7_R3.PlayerConnection.a(PlayerConnection.java:830) [craftcubbit.jar:git-Spigot-1.7.2-R0.3-178-g45eab08]
at net.minecraft.server.v1_7_R3.PacketPlayInChat.a(PacketPlayInChat.java:28) [craftcubbit.jar:git-Spigot-1.7.2-R0.3-178-g45eab08]
at net.minecraft.server.v1_7_R3.PacketPlayInChat.handle(PacketPlayInChat.java:65) [craftcubbit.jar:git-Spigot-1.7.2-R0.3-178-g45eab08]
at net.minecraft.server.v1_7_R3.NetworkManager.a(NetworkManager.java:176) [craftcubbit.jar:git-Spigot-1.7.2-R0.3-178-g45eab08]
at net.minecraft.server.v1_7_R3.ServerConnection.c(ServerConnection.java:77) [craftcubbit.jar:git-Spigot-1.7.2-R0.3-178-g45eab08]
at net.minecraft.server.v1_7_R3.MinecraftServer.v(MinecraftServer.java:713) [craftcubbit.jar:git-Spigot-1.7.2-R0.3-178-g45eab08]
at net.minecraft.server.v1_7_R3.DedicatedServer.v(DedicatedServer.java:283) [craftcubbit.jar:git-Spigot-1.7.2-R0.3-178-g45eab08]
at net.minecraft.server.v1_7_R3.MinecraftServer.u(MinecraftServer.java:576) [craftcubbit.jar:git-Spigot-1.7.2-R0.3-178-g45eab08]
at net.minecraft.server.v1_7_R3.MinecraftServer.run(MinecraftServer.java:482) [craftcubbit.jar:git-Spigot-1.7.2-R0.3-178-g45eab08]
at net.minecraft.server.v1_7_R3.ThreadServerApplication.run(SourceFile:628) [craftcubbit.jar:git-Spigot-1.7.2-R0.3-178-g45eab08]
Caused by: java.lang.NoClassDefFoundError: be/multicu/core/MultiCube
at Debug.debug(Debug.java:6) ~[?:?]
... 21 more
Caused by: java.lang.ClassNotFoundException: be.multicu.core.MultiCube
at java.net.URLClassLoader$1.run(URLClassLoader.java:366) ~[?:1.7.0_51]
at java.net.URLClassLoader$1.run(URLClassLoader.java:355) ~[?:1.7.0_51]
at java.security.AccessController.doPrivileged(Native Method) ~[?:1.7.0_51]
at java.net.URLClassLoader.findClass(URLClassLoader.java:354) ~[?:1.7.0_51]
at java.lang.ClassLoader.loadClass(ClassLoader.java:425) ~[?:1.7.0_51]
at java.lang.ClassLoader.loadClass(ClassLoader.java:358) ~[?:1.7.0_51]
at Debug.debug(Debug.java:6) ~[?:?]
... 21 more

谢谢你的帮助,乔巴

4

0 回答 0