Torchserve : java not found, please make sure JAVA_HOME is set properly

I am trying to run torchserve for a BERT based token classfier on Mac M1 Pro. I am getting the following error when i start tochserve with the command.

torchserve --start --ncs --model-store model_store --models all

java not found, please make sure JAVA_HOME is set properly.

JAVA_HOME is set and java is installed. These are the outputs for the following commands

  1. java -version

openjdk version β€œ19.0.2” 2023-01-17
OpenJDK Runtime Environment Homebrew (build 19.0.2)
OpenJDK 64-Bit Server VM Homebrew (build 19.0.2, mixed mode, sharing)

  1. echo $JAVA_HOME


How can I solve this issue ?

Not an an M1 right now but does this solve your problem?

export JAVA_HOME=$(/usr/libexec/java_home)

I have been unable to persistenly update JAVA_HOME on OSX so I am using the following to start TorchServe:

export JAVA_HOME=$(/usr/libexec/java_home -v 17); torchserve --start ..

However, I am unable to get any models to work, likely because M1 isn’t supported.

1 Like