我目前正在拥有一个具有多个依赖项的maven项目(包含在jar中)和一个位于其他地方的依赖项也编译为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
感谢您的帮助, 职吧