Making ANTLR generated class files into one jar file.

Posted by prosseek on Stack Overflow See other posts from Stack Overflow or by prosseek
Published on 2010-03-07T21:40:06Z Indexed on 2010/03/07 23:53 UTC
Read the original article Hit count: 337

Filed under:
|
|

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: Test
Caused by: java.lang.ClassNotFoundException: Test
        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.

© Stack Overflow or respective owner

Related posts about java

Related posts about antlr