After installing a Java 9 (EA) - in my case with brew cask install java9-beta
- it becomes the default:
$ ssh $USER@localhost /bin/sh
Password:
java -version
java version "9-ea"
Java(TM) SE Runtime Environment (build 9-ea+142)
Java HotSpot(TM) 64-Bit Server VM (build 9-ea+142, mixed mode)
For me this broke the artifactory service installed by homebrew. Continuing the above session:
/usr/local/opt/artifactory/libexec/bin/artifactory.sh
/usr/bin/java
-Djava.endorsed.dirs=/usr/local/Cellar/artifactory/5.1.4/libexec/tomcat/endorsed is not supported. Endorsed standards and standalone APIs
in modular form will be supported via the concept of upgradeable modules.
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
The brew services
command uses launchctl
, for example brew services start artifactory
creates a file
~/Library/LaunchAgents/homebrew.mxcl.artifactory.plist
, and the service shows up in launchctl list
:
$ launchctl list
...
5519 0 homebrew.mxcl.artifactory
...
The Status code will be non-zero if the service failed to start.
Running brew services stop artifactory
stops and removes the service.
To see the log output of the service startup, you can run:
sudo launchctl debug gui/$(id -u)/homebrew.mxcl.artifactory --stdout --stderr
With a Java 9 install, the same error as above should show up. To fix it, you need to set JAVA_HOME
to
a different version. This can be done by adding another service. Create a file ~/Library/LaunchAgents/set.java.home.plist
with the following content:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>set.java.home</string>
<key>ProgramArguments</key>
<array>
<string>sh</string>
<string>-c</string>
<string>
launchctl setenv JAVA_HOME `/usr/libexec/java_home -v 1.8`
</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
Then run launchctl load ~/Library/LaunchAgents/set.java.home.plist
. Maybe reboot your system.
To fix that more locally for just artifactory I've been editing
/usr/local/opt/artifactory/libexec/bin/artifactory.default
to include:export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home