How to make MATLAB read the environment variable JAVA_HOME
4 次查看(过去 30 天)
显示 更早的评论
My question is how do I make MATLAB read the environment variable JAVA_HOME.
I enter the Matlab command
jenv
and get the following answer
ans =
JavaEnvironment with properties:
Version: "Java 1.8.0_202-b08 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode"
Home: "/Applications/MATLAB_R2023a.app/sys/java/jre/maci64/jre"
Library: "/Applications/MATLAB_R2023a.app/sys/java/jre/maci64/jre/lib/server/libjvm.dylib"
Status: loaded
Configuration: "factory"
I enter the Matlab command
getenv JAVA_HOME
and get the following answer
ans = 0x0 empty char array
So I realize that for some reason JAVA_HOME has not been set properly. So I proceed to set the environement variable JAVA_HOME as instructed in:
I am running MATLAB on a Mac computer running IOS version 15.2, so according to the instructions I enter the following in ~/.zprofile
export JAVA_HOME="/Applications/MATLAB_R2023a.app/sys/java/jre/maci64/jre"
PATH="$JAVA_HOME/bin:${PATH}"
I do a echo $JAVA_HOME and I see the correct value for JAVA_HOME
but after restarting Matlab and entring in the command window
getenv JAVA_HOME
I still get
ans = 0x0 empty char array
Can anyone let me know what I am doing wrong, that MATLAB does not get the environment variable JAVA_HOME?
5 个评论
Walter Roberson
2025-4-21
.zshenv and .bash_profile are both related to interactive shells, and are not used when starting applications from icon or dock.
dpb
2025-4-21
So, you link the icon to a batch file that starts MATLAB from a shell, maybe?
What a mess...apparently at least one thing Bill's Boys did more simply.
回答(2 个)
Walter Roberson
2025-4-23
Potentially you could edit the .matlab7rc.sh file. See https://www.mathworks.com/help/matlab/ref/matlabmacos.html#bunueg9-5
3 个评论
Walter Roberson
2025-4-23
In MacOS, starting MATLAB from icon or dock is done by executing the shell script bin/matlab inside the MATLAB installation folder. So a shell script is executed -- just not an interactive shell script.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!