If I open the command prompt, go to my application folder and type the following:
java -version
I'll get the following result:
java version "11.0.8" 2020-07-14 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.8+10-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.8+10-LTS, mixed mode)
But if I go to Spring Tool Suite > right click project name on Project Explorer > Show in > Terminal > and type the same command (in the exact same folder as above):
java -version
I get a different result:
openjdk version "14.0.2" 2020-07-14
OpenJDK Runtime Environment (build 14.0.2+12-46)
OpenJDK 64-Bit Server VM (build 14.0.2+12-46, mixed mode)
How can it be?
Result when typing echo %PATH%
in the command line:
C:\Program Files\Java\jdk-11.0.8;C:\Program Files\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\Oberthur Technologies\AWP\Dlls;C:\Program Files\Oberthur Technologies\AWP\Dlls;C:\Program Files\Git\cmd;C:\Program Files\Java\jdk-11.0.8\bin;C:\Program Files\apache-maven-3.6.3\bin;C:\Program Files\MySQL\MySQL Shell 8.0\bin\;C:\Users\Samsung\AppData\Local\Microsoft\WindowsApps;C:\Program Files\heroku\bin
Result when typing echo %PATH%
in the STS terminal (same folder as above):
C:/spring-tool-suite-4-4.8.0/contents/sts-4.8.0.RELEASE//plugins/org.eclipse.justj.openjdk.hotspot.jre.full.
win32.x86_64_14.0.2.v20200815-0932/jre/bin/server;C:/spring-tool-suite-4-4.8.0/contents/sts-4.8.0.RELEASE//p
lugins/org.eclipse.justj.openjdk.hotspot.jre.full.win32.x86_64_14.0.2.v20200815-0932/jre/bin;C:\Program File
s\Java\jdk-11.0.8;C:\Program Files\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\Common Files\Ora
cle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerSh
ell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\Oberthur Technologies\AWP\Dlls;C:\Program File
s\Oberthur Technologies\AWP\Dlls;C:\Program Files\Git\cmd;C:\Program Files\Java\jdk-11.0.8\bin;C:\Program Fi
les\apache-maven-3.6.3\bin;C:\Program Files\MySQL\MySQL Shell 8.0\bin\;C:\Users\Samsung\AppData\Local\Micros
oft\WindowsApps;C:\Program Files\heroku\bin;C:\spring-tool-suite-4-4.8.0\contents\sts-4.8.0.RELEASE;
Disclaimer: The following answer is for Windows, and testing was done using Eclipse IDE 2020-12 for Enterprise Java Developers.
After some testing, I have found the following quirk regarding the PATH
of the Terminal.
In the eclipse.ini
file, you (can) specify which Java installation to use to run Eclipse itself, using the -vm
option. See: How to specify jdk path in eclipse.ini on windows 8 when path contains space
On older versions of Eclipse, the value was unspecified, which meant that Eclipse would use the default Java installation, i.e. the Java installation found on the PATH. In newer version of Eclipse, the value defaults to a JRE that ships as a plugin with Eclipse.
If the -vm
value is a directory, that directory is prepended to the PATH
when opening a Terminal using Ctrl+Alt+T in Eclipse, which means that the version of Java seen by the Terminal will be different from the version seen in a Command Prompt opening outside of Eclipse.
If the -vm
value is the fully qualified name to javaw.exe
, the PATH
is unaffected, i.e. it will be the same as the PATH
seen by a Command Prompt.
To check the PATH
used by Terminal, run command echo %PATH%
. Check the first entry to see if it refers to a particular Java installation.
If you want to ensure that Terminal has the same PATH
as you'd see in a Command Prompt, change the value of the -vm
option to fully qualify javaw.exe
.