18

I've been trying to set up javacc but am having problems. When I type javacc adder.jj (in the directory where adder.jj is) I am getting "'javacc' is not recognized as an internal or external command, operable program or batch file".

To my understanding I have to go to environmental variables, TEMP and change PATH to have C:\javacc-6.0\bin; added to the start. (I extracted the javacc zip to C:). I have tried this and restarted my computer with no luck. I also tried adding C:\javacc-6.0\bin\lib but again no luck. I did this when I installed java to get cmd to recognise javac and it worked!

This is probably trivial but I just can't get it to work!

Thank you

Henry

HBeel
  • 475
  • 2
  • 5
  • 12
  • From that article I got two things: first include the path which is inconvenient and for me didn't work. Or make the path permanent by adding it to system variables which from my question you can see I have tried. I hope you don't think I'm skimping research, forums are usually my last resort. http://i.imgur.com/XGNJo5U.png – HBeel Sep 07 '13 at 15:48

3 Answers3

39

In the version 6.0 the bin directory is missing the scripts which run javacc. That is why you are getting the error from the windows command prompt.

What you have is a jar file javacc.jar located in the lib directory. All you need is to add that jar file to your classpath and run the java.exe and pass the main class which runs javacc, the later happens to be named javacc too, so to run javacc just proceed like this:

cmd>  java -cp C:\javacc-6.0\bin\lib\javacc.jar javacc

In the latest version they seem to have forgotten to add the scripts in the bin folder of the package. You can download version 5.0, it containes all the script files you need, among others a file with the name javacc.bat, this is the one the window commad prompt is looking for and not finding in your case.

Of course, you can just copy those scripts from the 5.0 version to the bin directory of the 6.0 version, they will also work. and since you already have set the path to contain C:\javacc-6.0\bin then you can run it like you have tried before, without closing the command prompt window or even restarting your whole computer!

Edit - new links

The links above are unfortunately no longer valid, luckily the content has been moved to github. here the new links:

Project url: https://javacc.org/

Project url on github: https://javacc.github.io/javacc/

Earlier versions: https://github.com/javacc/javacc/branches/

A4L
  • 17,353
  • 6
  • 49
  • 70
  • Downgraded to version 5.0 worked a dream. Since I am starting out with javacc I can't see having a slighter older version being a problem. But thanks for the information for when I feel like upgrading to 6! edit: Just seen your edit, would of been easier but I'll just work with 5.0 Thanks again! – HBeel Sep 07 '13 at 16:14
  • 1
    To sum it up. Download javacc-6.0 then go to the command line and type in cmd. So if I have a .jj file I can do this. `java-cp C:\Users\me\Downloads\javacc-6.0\javacc-6.0\bin\lib\javacc.jar javacc C:\Users\me\FileIWantToRun.jj` – StreamingBits Nov 28 '14 at 21:37
  • 1
    @StreamingBits exactly! Or to avoid typing it each time, create your own `javacc.bat` file with the following content `java-cp C:\Users\me\Downloads\javacc-6.0\javacc-6.0\bin\lib\javacc.jar javacc %1` and call it like this `javacc.bat C:\Users\me\FileIWantToRun.jj` (.bat is optional since if omitted windows cmd searches for executables with the extensions listed in the environment variable `PATHEXT` (type in cmd `echo %PATHEXT%` to see what are those)). – A4L Nov 28 '14 at 23:49
  • 1
    The link is dead( – ChessMax Apr 22 '20 at 18:19
0

Solution

  • Download version 5.0, copy the files that come in the bin folder, except the lib folder (they are .bat files)
  • Paste those files in the same location, but in version 6.0 and resolved issue.

The error is that they did not add the executables in the bin folder.

skillsmuggler
  • 1,862
  • 1
  • 11
  • 16
-1
  1. open cmd
  2. cd to the directory where the javacc (calculator_2.jj) file loacted
  3. type in the cmd java -cp D:\S2018\CS661\javacc-6.0\javacc-6.0\bin\lib\javacc.jar javacc calculator_2.jj
silly
  • 887
  • 9
  • 9