Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 655195
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:34:38+00:00 2026-05-13T22:34:38+00:00

With ANTLR, I get some java class files after compilation. And I need to

  • 0

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 {
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T22:34:39+00:00Added an answer on May 13, 2026 at 10:34 pm

    What is the package namespace you used for Test class?

    Say, if your main class was pro.seek.Test,
    did you manifest it as

    Main-class: pro.seek.Test
    

    ?

    Antler would have produced a hierarchy of folders

    whatever/pro/seek
    

    so that your main class file is found at

    whatever/pro/seek/Test.java
    

    When you jarred the file, did you first cd to "whatever" folder first, so that you had the jar contents rooted at "pro" folder when you created the jar? So that, when you list the jar file with a zip viewer, you could see the hierarchy /pro/seek/, under which you would find your bunch of generated java source files.

    Did you create the jar file properly? Probably not an antlr issue, but a question on how to create an executable jar.

    From your inclusion of more information,

    here are further thoughts:

    You did not include the path to antlr distribution jar when you ran hello.jar.

    Either specify it in your manifest as

    Class-Path: antlr-3.1.1-runtime.jar
    

    or specify it when you run hello.jar as

    jar hello.jar -classpath antlr-3.1.1-runtime.jar
    

    and make sure the antlr jar is there next to hello.jar.

    When your java source code uses any libraries during compilation, those libraries have to be included when you run the compiled code, which should be pretty obvious rule because the computer needs to know what to do with those calls being made to the library routines.

    Say, someone wrote a routine showMe(boolean theTruth) in a class Truth and placed it a jar truth.jar:

    public class Truth{
      static public void showMe(boolean theTruth){
        if (theTruth)
           println("It's a lie");
        else
           println("Thanks for the truth");
      }
    }
    

    And your Test.java has a call

    Truth.showMe(false);
    

    you have to include Truth.jar, otherwise how would the jvm know what to do with the call to showMe()?

    Antlr produces a bunch of java source files and they have calls to the antlr runtime, therefore you need to include the antlr run-time in your runtime classpath. Your run-time error shows that the jvm is looking for org.antlr.runtime.CharStream class which is found in the antrl run-time jar.

    http://java.sun.com/docs/books/tutorial/deployment/jar/downman.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to analyze some C++ source files in order to generate some very
I have a line number of a Java source file and want to get
I need a small trick to get my parser completely working. I use antlr
I'm trying to update a file in an existing jar (in this example antlr)
I'm currently using AntLR to parse some files with a proprietary language. I have
I have an ANTLR grammar file as part of a C# project file and
I need to match in ANTLR a message containing 2 fields separated by a
I have an antlr generated Java parser that uses the C target and it
I'm trying to use Antlr for some text IDE-like functions -- specifically parsing a
I've been trying to learn ANTLR and get it working with C output code

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.