I'm trying to compile a tiny hello.g4 grammar file using ANTLR 4.8 on Windows 10. My end target is to run ANTLR inside of Visual Studio.
The problem is that something is happening to prevent me from running the generate, compile, execute sequence with constant PATH settings. I don't know enough about how Java works to determine what is wrong (or how to fix it).
The location of the latest Java SDK 14.0 files:
c:\program files\...\sdk 14.0\(a pile of files including java.exe and javac.exe)
The original Java 8 runtime location:
c:\program files (x86)\common files\Oracle\java\javapath (three files java.exe, javaw.exe, etc.)
The classpath points to my working directory (where the ANTLR java files are generated) and to the ANTLR jar file itself. The ANTLR complete jar file is in the same directory as everything else. The examples below both use the same CLASSPATH setting.
CLASSPATH=.;c:\dev\bin\antlr-4.8-complete.jar
I do not have JRE_HOME or JAVA_HOME or any such environment variables set. Only CLASSPATH and PATH.
A WORKING SEQUENCE
This sequence works (indicating that the grammar and tools work)
PATH=(the Java8 runtime location);(the SDK location);... other paths
// generate the parser with the SDK path explicitly (with PATH=Java8 in front)
"C:\Program Files\Java\jdk-14.0.2\bin\java" org.antlr.v4.Tool hello.g4
// now switch the PATH variable to put the SDK first
// this compiles and runs the generated files successfully
PATH=(the SDK location);(the Java8 runtime location);... other paths
"C:\Program Files\Java\jdk-14.0.2\bin\javac" hello*.java
"C:\Program Files\Java\jdk-14.0.2\bin\java" org.antlr.v4.gui.TestRig %*
A FAILED SEQUENCE
CLASSPATH=.;c:\dev\bin\antlr-4.8-complete.jar (unchanged from above)
If the SDK is first in the path, generation works, but compilation fails
PATH=(the SDK location);(the Java8 runtime location);... other paths
OK: "C:\Program Files\Java\jdk-14.0.2\bin\java" org.antlr.v4.Tool hello.g4
FAILS: "C:\Program Files\Java\jdk-14.0.2\bin\javac" hello*.java
Hundreds of errors are generated, among them ones like this.
fooLexer.java:6: error: package org.antlr.v4.runtime does not exist
import org.antlr.v4.runtime.*;
^
I have no files named org.antlr.v4.runtime; could it/they be in the antlr.4.8.complete.jar file or something?
The Java8 PATH must be first for the generation phase The SDK PATH must be first for the compilation and execution phases.
I'm also just using a command line window to run the commands - no IDE is involved.
Can anyone tell me how to fix things so that I can run a generation, compile, execution cycle without flipping my PATH variable? Thank you. PS. I have read half a dozen potentially "duplicate" questions here on SO, but they all involve a different setup (with IDEs) and nothing I tried from them worked for me.