@@ -59,7 +59,10 @@ Matlab function.
5959Tell JVM details:
6060
6161``` matlab
62- jenv
62+ je = jenv
63+
64+ % Tell the JAVA_HOME directory
65+ disp(je.Home)
6366```
6467
6568For example, to use the
@@ -91,23 +94,55 @@ For example, with Homebrew:
9194brew install octave openjdk
9295```
9396
97+ On Windows install JDK as like Matlab above.
98+
99+ ``` octave
100+ setenv("JAVA_HOME", "/path/to/openjdk/")
101+ ```
102+
103+ This ` setenv() ` is not persistent.
104+ If it works, add the working ` setenv() ` command to
105+ [ .octaverc] ( https://docs.octave.org/interpreter/Startup-Files.html )
106+
107+ ### Use Matlab JRE in GNU Octave
108+
109+ If Matlab is installed, GNU Octave can use the same JRE as Matlab.
110+ Do so like:
111+
112+ ``` matlab
113+ je = jenv();
114+ % Tell the JAVA_HOME directory
115+ disp(je.Home)
116+ ```
117+
118+ Then set the JAVA_HOME environment variable to the JRE directory in Octave:
119+
120+ ``` octave
121+ setenv("JAVA_HOME", "value from je.Home")
122+ ```
123+
124+ Be sure on Windows to use file separator "/" as "\" will not work.
125+ Within Octave:
126+
127+ ``` octave
128+ setenv("JAVA_HOME", "C:/Program Files/MATLAB/R2025a/sys/java/jre/win64/jre")
129+
130+ version("-java")
131+ ```
132+
133+ > ans = Java 1.8.0_202-b08 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode
134+
135+ ### Troubleshooting
136+
94137If OpenJDK version updates, GNU Octave might not automatically find the new version:
95138
96139> libjvm: failed to load
97140
98- To correct this, find the path to the new JVM.
99- Windows installs Java with Octave, so this usually isn't needed.
141+ To correct this, find the path to the new JVM..
100142For example, on macOS:
101143
102144``` sh
103145gfind $( brew --prefix) -name libjvm.dylib
104146```
105147
106- Within Octave, tell Octave the directory that libjvm is under.
107- This setting is not persistent.
108- If it works, add the setenv() command to
109- [ .octaverc] ( https://docs.octave.org/interpreter/Startup-Files.html )
110-
111- ``` octave
112- setenv("JAVA_HOME", "/path/to/openjdk/")
113- ```
148+ Within Octave, tell Octave the directory that libjvm is under by ` setenv("JAVA_HOME", "<path to libjvm directory>") ` .
0 commit comments