javapathjavacc

Setting javacc to work with command prompt


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


Solution

  • 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/