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 7826867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T09:36:26+00:00 2026-06-02T09:36:26+00:00

I have a project due soon and everything is coming together really nicely, but

  • 0

I have a project due soon and everything is coming together really nicely, but java classpaths are getting seriously in the way. I’ll try to explain the situation as clearly and thoroughly as I can.

So we are using Javacc to write a programming language. The javacc file compiles into several java files. The Parser.java file includes references and calls to the other generated java files. So, after generation, we compile the Parser.java file. The problem is we get many errors, including not being able to recognize the calls to the other java files as well as our own files. We asked on a classroom discussion board about our problem and the professor responded with “you need to have the class files in your classpath”. Ok, great, so the question is, how do we do that? Basically we have a single directory with the generated java files and our other helper files.

So, what have we tried?

I have tried changing my .bashrc (Ubuntu) file to include the correct classpath but that doesn’t work. i.e.

 CLASSPATH=Home/project

(something like that I had the syntax right in the file)

I’ve tried on compilation executing

javac -cp . Parser.java

and

javac -cp "." Parser.java

neither works.

I have tried to edit the xml (I think xml) .classpath file in the directory of our files. Still doesn’t work.

Somehow, I was able to compile Parser.java in one of the directories I have (we ended up making multiple directories with the same files in it in a futile effort to make something work) but when I try to run

java -cp . Parser.java

or

java Parser.java

It says it can not find the main and throws (I believe, its on my other computer) ClassNotFound or ClassNotDefined exception (something like that, it cannot find the main in the Parser file eventhough it IS there).

We have tried adding packages deceleration and import statements to our file, nothing seems to work.

BASICALLY: How can I successfully change the Classpath so that my java files (all in one directory and not jarred) can be compiled and run on my machine?

Thank you for your help. I greatly appreciate it.

  • 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-06-02T09:36:28+00:00Added an answer on June 2, 2026 at 9:36 am

    I highly suggest you look into Ant. A simple build file can solve all these problems for you.

    You don’t need to edit your .bashrc or CLASSPATH.

    From the command line you need to build ALL the java files together. I am not sure if JavaCC needs javacc.jar after it’s generated your Lexer and Parser. But let’s assume it does for some generic AST support.

    javacc.jar is located in ~/javacc-5.0/lib/javacc.jar

    Scenario 1: Simple directory structure, all Java files are in the root folder with no package.

    root
      | Parser.java
      | Lexer.java
      | Program.java
    

    To compile these I need to run:

    javac -cp ~/javacc-5.0/lib/javacc.jar Parser.java Lexer.java Program.java

    then I can execute Program like so if Program has main

    java -cp ~/javacc-5.0/lib/javacc.jar:. Program

    Scenario 2: Medium directory structure, code in root but with packages.

    root
      | org
         | myproject
              | Parser.java
              | Lexer.java
              | Program.java
    

    then you need to execute javac like so:

    javac -cp ~/javacc-5.0/lib/javacc.jar org/myproject/Parser.java org/myproject/Lexer.java org/myproject/Program.java

    and to execute

    java -cp ~/javacc-5.0/lib/javacc.jar:. org.myproject.Program

    Scenario 3: Complex directory structure, specific source directory with packages.

    root
       | src
          | org
              | myproject
                  | Parser.java
                  | Lexer.java
                  | Program.java
    

    then you need to execute javac like so:

    javac -cp ~/javacc-5.0/lib/javacc.jar -sourcepath src src/org/myproject/Parser.java src/org/myproject/Lexer.java src/org/myproject/Program.java

    and to execute

    java -cp ~/javacc-5.0/lib/javacc.jar:src org.myproject.Program

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

Sidebar

Related Questions

I currently have the DatePicker in my project but there are problems due to
I have a project due soon about using signals and sighandlers and I'm essentially
I have this project that it's due in a few hours and I still
I have a maven project which won't compile due to an unresolvable reference from
I have a Silverlight project where functionality is segregated across multiple Silverlight libraries due
I have a C++ project that due to its directory structure is set up
I added and have been using the faces-config.xml in my Netbeans 6.9/JSF2.0 project due
I have a project that's currently in a Perforce repository. Unfortunately, due to some
So I have a project of which I want to switch to Astar due
I have project Emle in Launchpad . I set it to import from emle.svn.sourceforge.net

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.