Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting javacc to work with command prompt

Tags:

java

path

javacc

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

like image 817
HBeel Avatar asked Sep 07 '13 14:09

HBeel


People also ask

Why javac is not working in CMD?

javac is not recognized is an error occurs while we compile the Java application. It is because the JVM is unable to find the javac.exe file. The javac.exe file is located in the bin folder of the JDK. The reason behind to occur the error is that the PATH is not added to the System's environment variable.

Why is my Java program not compiling?

It means that javac.exe executable file, which exists in bin directory of JDK installation folder is not added to PATH environment variable. You need to add JAVA_HOME/bin folder in your machine's PATH to solve this error. You cannot compile and run Java program until your add Java into your system's PATH variable.

How do you solve javac is not recognized as an internal or external command?

It means that the javac.exe executable file, which exists in the bin directory of the JDK installation folder is not added to the PATH environment variable. You need to add the JAVA_HOME/bin folder in your machine's PATH to solve this error.


1 Answers

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/

like image 103
A4L Avatar answered Sep 20 '22 15:09

A4L