<dependencies>
<dependency org="org.apache.commons" name="commons-math3" rev="3.2"/>
<dependency org="org.antlr" name="antlr4" rev="4.0"/>
<dependency org="org.antlr" name="antlr4-runtime" rev="4.0"/>
<dependency org="org.antlr" name="antlr4-master" rev="4.0"/>
</dependencies>
我使用 Ivy 使用 ant 脚本将上面的依赖 jar 下载到 lib 目录中。
antlr4-4.0.jar
是这些依赖项之一。但是当我在终端中这样做时:
java -cp antlr4-4.0.jar org.antlr.v4.Tool
我得到这个例外:
Exception in thread "main" java.lang.NoClassDefFoundError: org/antlr/v4/runtime /misc/ParseCancellationException
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:787)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:447)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2451)
at java.lang.Class.getMethod0(Class.java:2694)
at java.lang.Class.getMethod(Class.java:1622)
at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:494)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:486)
Caused by: java.lang.ClassNotFoundException: org.antlr.v4.runtime.misc.ParseCancellationException
... 25 more
我究竟做错了什么?