Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error ANT02: Cannot find Java executable'' on MacOS #49

Open
rstm-sf opened this issue Nov 6, 2022 · 5 comments
Open

error ANT02: Cannot find Java executable'' on MacOS #49

rstm-sf opened this issue Nov 6, 2022 · 5 comments

Comments

@rstm-sf
Copy link

rstm-sf commented Nov 6, 2022

<TargetFramework>netstandard2.1</TargetFramework>

https://github.com/rstm-sf/qsharp-compiler/blob/infra/use_Antlr4BuildTasks/src/QsFmt/Parser/Parser.csproj

16>Antlr4Compile:
    Running the Java Antlr Tool over the grammar files '/Users/runner/work/1/s/src/QsFmt/Parser/../../../qsharp-language/Specifications/Language/5_Grammar/QSharpLexer.g4;/Users/runner/work/1/s/src/QsFmt/Parser/../../../qsharp-language/Specifications/Language/5_Grammar/QSharpParser.g4'.
    Starting Antlr4 Build Tasks.
    Placing generated files in IntermediateOutputPath /Users/runner/work/1/s/src/QsFmt/Parser/obj/Release/netstandard2.1/
    Antlr4BuildTasks identified that you are looking for version 4.11.1 of the Antlr4 tool jar.
    Version '4.11.1' v2 match='', v3 match='4.11.1'
    Location to stuff Antlr tool jar, if not found, is /Users/runner/.m2/
    Paths to search for Antlr4 jar, in order, are: file:////Users/runner/.m2/;file:////Users/runner/work/1/s/src/QsFmt/Parser/obj/Release/netstandard2.1/;https://repo1.maven.org/maven2/org/antlr/antlr4/
    path is file:////Users/runner/.m2/
    place_path is /Users/runner/.m2/
    Probing file:////Users/runner/.m2/antlr4-4.11.1-complete.jar
    Local path \\users\runner\.m2\antlr4-4.11.1-complete.jar
    path is file:////Users/runner/work/1/s/src/QsFmt/Parser/obj/Release/netstandard2.1/
    place_path is /Users/runner/.m2/
    Probing file:////Users/runner/work/1/s/src/QsFmt/Parser/obj/Release/netstandard2.1/antlr4-4.11.1-complete.jar
    Local path \\users\runner\work\1\s\src\QsFmt\Parser\obj\Release\netstandard2.1\antlr4-4.11.1-complete.jar
    path is https://repo1.maven.org/maven2/org/antlr/antlr4/
    place_path is /Users/runner/.m2/
    Probing https://repo1.maven.org/maven2/org/antlr/antlr4/4.11.1/antlr4-4.11.1-complete.jar
    archive_name is /Users/runner/.m2/antlr4-4.11.1-complete.jar
    place_path is /Users/runner/.m2/
    Downloading https://repo1.maven.org/maven2/org/antlr/antlr4/4.11.1/antlr4-4.11.1-complete.jar
    archive_name is /Users/runner/.m2/antlr4-4.11.1-complete.jar
    place_path is /Users/runner/.m2/
    Found /Users/runner/.m2/antlr4-4.11.1-complete.jar
    AntlrToolJar is "/Users/runner/.m2/antlr4-4.11.1-complete.jar"
    Location to stuff JRE, if not found, is /Users/runner/.jre/
    Paths to search for the java executable, in order, are: PATH;DOWNLOAD
    path is PATH
    Executing command: "/usr/bin/java" --version
    Unrecognized option: --version
    Error: Could not create the Java Virtual Machine.
    Error: A fatal exception has occurred. Program will exit.
    java found at '/usr/bin/java', but it doesn't work.
    path is DOWNLOAD
    Probing DOWNLOAD
    Downloading OpenJDK11U-jre_x64_linux_hotspot_11.0.15_10.tar.gz
    Completed downloading of OpenJDK11U-jre_x64_linux_hotspot_11.0.15_10.tar.gz
    Found /Users/runner/.jre/OpenJDK11U-jre_x64_linux_hotspot_11.0.15_10.tar.gz
    Java should be here /Users/runner/.jre/jdk-11.0.15+10-jre/bin/java
    Decompressing
    full path "/Users/runner/.jre/jdk-11.0.15+10-jre/"
    Executing command: "/usr/bin/chmod" 755 /Users/runner/.jre/jdk-11.0.15+10-jre/
16>/Users/runner/.nuget/packages/antlr4buildtasks/11.5.0/build/Antlr4BuildTasks.targets(133,3): error ANT02: Cannot find Java executable''   at Antlr4.Build.Tasks.RunAntlrTool.SetupJava() [/Users/runner/work/1/s/src/QsFmt/Parser/Parser.csproj]
    /Users/runner/.nuget/packages/antlr4buildtasks/11.5.0/build/Antlr4BuildTasks.targets(133,3): error ANT02:    at Antlr4.Build.Tasks.RunAntlrTool.Execute() [/Users/runner/work/1/s/src/QsFmt/Parser/Parser.csproj]
16>/Users/runner/.nuget/packages/antlr4buildtasks/11.5.0/build/Antlr4BuildTasks.targets(133,3): error ANT02: The Antlr4 tool failed. [/Users/runner/work/1/s/src/QsFmt/Parser/Parser.csproj]
16>Done Building Project "/Users/runner/work/1/s/src/QsFmt/Parser/Parser.csproj" (default targets) -- FAILED.

https://dev.azure.com/ms-quantum-public/Microsoft%20Quantum%20(public)/_build/results?buildId=46269&view=results

@kaby76
Copy link
Owner

kaby76 commented Nov 6, 2022

Sorry, I don't usually use MacOS, and I don't think I have a CI test for it yet. For now, make sure to install OpenJDK v11 or newer, and add it to your path. The one at /usr/bin/java is old, and doesn't even accept a --version option to test what version it is. That's why it downloads a .gz file--albeit the wrong one for MacOS.

Also, I don't know if the package takes "*.g4". I do globbing, but I don't know if it's done on the .g4's. You may need to replace with each grammar file. I'll check this and add it in the next release.

@rstm-sf
Copy link
Author

rstm-sf commented Nov 6, 2022

Also, I don't know if the package takes "*.g4". I do globbing, but I don't know if it's done on the .g4's. You may need to replace with each grammar file. I'll check this and add it in the next release.

It works for windows and linux. The link to the pipeline builds passed :)

@emmekappa
Copy link

emmekappa commented Nov 21, 2023

still have the same issue on MacOS

         Version '4.13.1' v2 match='', v3 match='4.13.1'
         Location to stuff Antlr tool jar, if not found, is /Users/emmekappa/.m2/
         Paths to search for Antlr4 jar, in order, are: file:////Users/emmekappa/.m2/;file:////Users/emmekappa/dev/AntlrStep1/AntlrStep1/obj/Debug/netstandard2.1/;https://repo1.maven.org/maven2/org/antlr/antlr4/
         path is file:////Users/emmekappa/.m2/
         place_path is /Users/emmekappa/.m2/
         Probing file:////Users/emmekappa/.m2/antlr4-4.13.1-complete.jar
         Local path \\users\emmekappa\.m2\antlr4-4.13.1-complete.jar
         path is file:////Users/emmekappa/dev/AntlrStep1/AntlrStep1/obj/Debug/netstandard2.1/
         place_path is /Users/emmekappa/.m2/
         Probing file:////Users/emmekappa/dev/AntlrStep1/AntlrStep1/obj/Debug/netstandard2.1/antlr4-4.13.1-complete.jar
         Local path \\users\emmekappa\dev\AntlrStep1\AntlrStep1\obj\Debug\netstandard2.1\antlr4-4.13.1-complete.jar
         path is https://repo1.maven.org/maven2/org/antlr/antlr4/
         place_path is /Users/emmekappa/.m2/
         Probing https://repo1.maven.org/maven2/org/antlr/antlr4/4.13.1/antlr4-4.13.1-complete.jar
         archive_name is /Users/emmekappa/.m2/antlr4-4.13.1-complete.jar
         place_path is /Users/emmekappa/.m2/
         Found /Users/emmekappa/.m2/antlr4-4.13.1-complete.jar
         AntlrToolJar is "/Users/emmekappa/.m2/antlr4-4.13.1-complete.jar"
         Search path for java (JavaExec): PATH;DOWNLOAD
         Download area for JRE (JavaDownloadDirectory): /Users/emmekappa/.jre/
         Paths to search for the java executable, in order, are: PATH;DOWNLOAD
         probing java executable at PATH
         Path to try is PATH
         Trying PATH
         found a java executable at /usr/bin/java
         w = /usr/bin/java
         Executing command: "/usr/bin/java" -version
         got data java version "21.0.1" 2023-10-17 LTS
         got data 
         got data Java(TM) SE Runtime Environment (build 21.0.1+12-LTS-29)
         got data Java HotSpot(TM) 64-Bit Server VM (build 21.0.1+12-LTS-29, mixed mode, sharing)
         got data 
         java at '/usr/bin/java', but not a good version.
         java not found on path
         probing java executable at DOWNLOAD
         Path to try is DOWNLOAD
         Probing DOWNLOAD
         Trying pattern USERPROFILE/.jre/.*/java
         os_arch is Unix 14.1.1
         os_arch str is 
         os_arch is Unix 14.1.1
         os_arch is Unix 14.1.1
         os_arch is Unix 14.1.1
         os_arch is Unix 14.1.1
         os_arch is Unix 14.1.1
         os_arch is Unix 14.1.1
   1:7>/Users/emmekappa/.nuget/packages/antlr4buildtasks/12.4.0/build/Antlr4BuildTasks.targets(138,9): error ANT02: Cannot find Java executable''   at Antlr4.Build.Tasks.RunAntlrTool.SetupJava() [/Users/emmekappa/dev/AntlrStep1/AntlrStep1/AntlrStep1.csproj]
/Users/emmekappa/.nuget/packages/antlr4buildtasks/12.4.0/build/Antlr4BuildTasks.targets(138,9): error ANT02:    at Antlr4.Build.Tasks.RunAntlrTool.Execute() [/Users/emmekappa/dev/AntlrStep1/AntlrStep1/AntlrStep1.csproj]
   1:7>/Users/emmekappa/.nuget/packages/antlr4buildtasks/12.4.0/build/Antlr4BuildTasks.targets(138,9): error ANT02: The Antlr4 tool failed. [/Users/emmekappa/dev/AntlrStep1/AntlrStep1/AntlrStep1.csproj]
       Esecuzione attiv

@kaby76
Copy link
Owner

kaby76 commented Nov 21, 2023

@emmekappa It seems the version information checking in this package needs to be fixed.

         found a java executable at /usr/bin/java
         w = /usr/bin/java
         Executing command: "/usr/bin/java" -version
         got data java version "21.0.1" 2023-10-17 LTS

The package tries to run java and test the version produced. That's because people install java that isn't version 11 or newer. In your case, you installed Sun's official SE java. With the "antlr4" tool in antlr4-tools, Parr just tests if java runs, which isn't quite good enough.

This need to be fixed. I'll have something later today.

kaby76 added a commit that referenced this issue Nov 22, 2023
"Can't find Java" caused because Oracle's JDK has a different version string. I updated the pattern match with a Regex with these strings as well as for the OpenJDK. Clean up.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants