OS: macOS 12.4
I got a similar error: /opt/homebrew/bin/confluent-hub: line 13: cd: /opt/homebrew/bin/../share/java: No such file or directory Error: Could not find or load main class io.confluent.connect.hub.cli.ConfluentHubClient
I can see that the /opt/homebrew/bin/confluent-hub
has symbolic links to /opt/homebrew/Caskroom/confluent-hub-client/7.1.1/bin/confluent-hub
. Then I looked into the code in /opt/homebrew/Caskroom/confluent-hub-client/7.1.1/bin/confluent-hub
file :
#!/usr/bin/env bash
# (Copyright) [2018 - 2018] Confluent, Inc.
base_dir=$(dirname $0)
if [ -L /usr/local/bin/confluent-hub ]; then <<= line 9: I don't have this file and it should be a symbolic link to /opt/homebrew/Caskroom/confluent-hub-client/7.1.1/bin/confluent-hub
#brew cask installation
base_dir=$(dirname $( ls -l /usr/local/bin/confluent-hub | awk '{print $11}' ))
#base_dir refers to Caskrooom/confluent-hub-client
fi
#cd -P deals with symlink from /bin to /usr/bin
java_base_dir=$( cd -P "$base_dir/../share/java" && pwd ) <<= line 13: where error thrown
HUB_CLI_CLASSPATH="${HUB_CLI_CLASSPATH}:${java_base_dir}/confluent-hub-client/*"
BIN_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
exec java -cp "${HUB_CLI_CLASSPATH}" -Dbin.abs.path="${BIN_DIR}" io.confluent.connect.hub.cli.ConfluentHubClient "$@"
Since there is no such file/symbolic link at line 9, the code jumps to line 13 straightaway and starts complaining the java binary file not found. Without going inside the if statement, the current $base_dir = /opt/homebrew/bin
and there is no /opt/hombrew/share/java
file.
Actually the java file is at /opt/homebrew/Caskroom/confluent-hub-client/7.1.1/share/java/
. We have to let the code goes inside the if statement so that $base_dir can get overwritten to use the right path as of /opt/homebrew/Caskroom/confluent-hub-client/7.1.1/bin
.
In order to ensure that the code executes inside the if else statement, I manually created a symbolic link: sudo ln -s /opt/homebrew/Caskroom/confluent-hub-client/<CONFLUENT-HUB-VERSION>/bin/confluent-hub /usr/local/bin/confluent-hub
. Then problem solved.