"brew services start tomcat" is ignoring ~/.zshrc environmental variables

955 Views Asked by At

I'm installing java8 and tomcat9 like this:

brew install adoptopenjdk/openjdk/adoptopenjdk8 --cask
ln -s $(/usr/libexec/java_home -v 1.8) /opt/homebrew/opt/openjdk 
echo 'export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)' >> ~/.zshrc

brew install tomcat@9 --ignore-dependencies
brew services start tomcat@9

I export the location of java to a environmentan variable called JAVA_HOME stored in my user ~/.zshrc file because catalina.sh needs the environmentan variable JAVA_HOME setted to work.

If i start catalina.sh using terminal, works perfectly, but brew services start tomcat@9 doesn't work because the launchctl service ignores the environmentan variable called JAVA_HOME stored in my user ~/.zshrc file. So it is ignoring the ~/.zshrc file.

In Mac OSX Catalina this worked perfectly, but it's failing in Monterey

1

There are 1 best solutions below

0
On

This worked for me on Monterey:

echo 'export JAVA_HOME=$(/usr/libexec/java_home)' >> ~/.zshrc
echo 'launchctl setenv JAVA_HOME $JAVA_HOME' >> ~/.zshrc
. ~/.zshrc
brew services run tomcat@9

See this answer if you want it to persist across reboots, not an issue for me as I rarely reboot and prefer to start Tomcat manually.