如何最好地在windows中设置java的路径 [英] How to best set the path to java in windows

查看:78
本文介绍了如何最好地在windows中设置java的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很好奇我在windows环境中看到的java路径之间存在的差异.如果我执行命令 where java 我可以看到

I'm curious about the difference that exists between the paths that I see in the windows environment to java. If I do a command where java I can see

C:\Program Files (x86)\Common Files\Oracle\Java\javapath\java.exe
C:\ProgramData\Oracle\Java\javapath\java.exe
C:\Program Files\Java\jdk1.6.0_21\bin\java.exe

而且我已经看到第一个 javapath 使用我安装的最新 java sdk 进行了更新.但是,您谷歌告诉您的大部分内容都应该将环境变量 PATH 设置为最新的,即路径中带有 jdk 的那个.那么什么是最好的,它们是如何工作的.例如,什么最适合 Xamarin 或 Android 开发?

And I have seen that the first one, the javapath, gets updated with the latest java sdk I have installed. However, most of what you google tells you should set the environment variable PATH to the latest, the one with the jdk in the path. So what is the best, how do they work. For example, what's best for Xamarin or Android development?

希望有人有一些见解,我很感激对此发表评论.现在我知道,(每个人都知道)要更改 java 的路径,您必须设置 JAVA_HOME 变量.我在发布这篇文章后做了这个,很难回忆起你在任何特定时刻读过的一切!还是其他路径的目的是什么,为什么更新java jre会自动设置java版本,而下载sdk需要手动更新?

Hopefully someone has some insight, I'd appreciate comments on this. Now I know, (everyone does) that to change the path to java you have to set the JAVA_HOME variable. I did this after posting this, it's hard to recall everything you read at any given moment! Still what's the purpose of the other paths, and why does updating java jre automatically sets the java version while downloading an sdk requires a manual update?

推荐答案

安装新版本的 JRE 时,此路径 C:\Program Files (x86)\Common Files\Oracle\Java似乎使用与新 JRE 版本相对应的可执行文件进行了更新.问题是这将是 JRE 而不是 JDK.因此,依赖 JDK(例如 IDE)的程序将无法启动.

When a new version of JRE is installed, this path C:\Program Files (x86)\Common Files\Oracle\Java appears to be updated with executables corresponding to the new JRE version. The problem is this would be JRE and not JDK. So, programs that depend on JDK (IDE for example) will fail to launch.

这是我如何让它始终如一地工作

  1. 我总是在用户变量中有一个环境变量(进入控制面板的系统环境变量 -> 系统 -> 高级系统设置 -> 环境变量 -> 用户变量)-- JAVA_HOME 指向 JDK 主页.并将 %JAVA_HOME%\bin 添加到 PATH 环境变量中.
  2. 有趣的是,我从 System 中的 Path 环境变量中删除了条目 C:\Program Files (x86)\Common Files\Oracle\Java\javapath环境变量(控制面板 -> 系统 -> 高级系统设置 -> 环境变量 -> 系统变量).
  1. I always have an environment variable in User Variables (System Environment Variables by going to Control Panel -> System -> Advanced System Settings -> Environment Variables -> User Variables) -- JAVA_HOME pointing to the JDK Home. And add %JAVA_HOME%\bin to the PATH environment variable.
  2. Interestingly, I remove the entry C:\Program Files (x86)\Common Files\Oracle\Java\javapath from the Path environment variable in System Environment Variables (Control Panel -> System -> Advanced System Settings -> Environment Variables -> System Variables).

自 2020 年 8 月起适用于 Windows 10 (1903)、Java 8u251.:)

This works as of Aug 2020 for Windows 10 (1903), Java 8u251. :)

这篇关于如何最好地在windows中设置java的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆