With ANTLR, I get some java class files after compilation. And I need to make all the class files into one jar file.
I make manifest.mf file that has one line "Main-class: Test" to indicate the main file. I run 'jar cmf manifest.mf hello.jar *.class' to get hello.jar file.
But when I try to run 'java -jar hello.jar', I get the following error messages.
$ java -jar hello.jar Exception in thread "main" java.lang.NoClassDefFoundError: org/antlr/runtime/CharStream Caused by: java.lang.ClassNotFoundException: org.antlr.runtime.CharStream at java.net.URLClassLoader$1.run(URLClassLoader.java:200) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:188) at java.lang.ClassLoader.loadClass(ClassLoader.java:315) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:330) at java.lang.ClassLoader.loadClass(ClassLoader.java:250) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:398)
What's wrong? I get correct result when I run 'java Test'.
The example that I used is the source code from the book 'The Definitive ANTLR Reference' that you can download from http://www.pragprog.com/titles/tpantlr/source_code
The example is in /tour/trees/. I get a bunch of class files after compiling g and java files.
Using unzip -l, I get the following info.
Archive: hello.jar Length Date Time Name -------- ---- ---- ---- 0 03-07-10 17:51 META-INF/ 78 03-07-10 17:51 META-INF/MANIFEST.MF 5872 03-07-10 14:05 Eval.class 1020 03-07-10 14:05 ExprLexer$DFA5.class 5713 03-07-10 14:05 ExprLexer.class 429 03-07-10 14:05 ExprParser$atom_return.class 429 03-07-10 14:05 ExprParser$expr_return.class 437 03-07-10 14:05 ExprParser$multExpr_return.class 429 03-07-10 14:05 ExprParser$prog_return.class 429 03-07-10 14:05 ExprParser$stat_return.class 11048 03-07-10 14:05 ExprParser.class 1129 03-07-10 14:05 Test.class -------- ------- 27013 12 files
The Test.java starts as follow.
import org.antlr.runtime.*;
import org.antlr.runtime.tree.*;
public class Test {
public static void main(String[] args) throws Exception {