Not sure if your issue is similar. I had openJDK installed through homebrew but the macOS didn't recognize it. Every time I tried to run java it complained that "The operation couldn’t be completed. Unable to locate a Java Runtime. Please visit http://www.java.com for information on installing Java."
For macOS /usr/bin/java wrapper to find the installed JDK, manually create a symbolic link at /Library/Java/JavaVirtualMachines/, like "sudo ln -sfn /opt/homebrew/Cellar/openjdk/18.0.1.1/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk". After that the brew installed jdk was recognized properly.