如何设置Java环境变量在Windows(类路径)?
当前回答
Java SE Development Kit 8u112, 64位Windows 7或Windows 8
设置以下用户环境变量(==类型为用户变量的环境变量)
JAVA_HOME: C:\Program Files\Java\ jdk1.8.0_112 Jdk_home: % java_home % JRE_HOME: %JAVA_HOME%\jre 类路径:.;%JAVA_HOME%\lib 路径:your-unique-entries;%JAVA_HOME%\bin(确保较长的your-unique-entries不包含对其他Java安装文件夹的任何其他引用。
64位系统的Windows用户注意:
Progra~1 = 'Program Files'
Progra~2 = 'Program Files(x86)'
注意,这些环境变量派生自“根”环境变量JAVA_HOME。这使得在更新JDK时可以很容易地更新环境变量。只需将JAVA_HOME指向新的安装。
有一篇博文解释了所有这些环境变量背后的基本原理。
可选的建议
Add a user environment variable JAVA_TOOL_OPTIONS with value -Dfile.encoding="UTF-8". This ensures that Java (and tools such as Maven) will run with a Charset.defaultCharset() of UTF-8 (instead of the default Windows-1252). This has saved a lot of headaches when wirking with my own code and that of others, which unfortunately often assume the (sane) default encoding UTF-8. When JDK is installed, it adds to the system environment variable Path an entry C:\ProgramData\Oracle\Java\javapath;. I anecdotally noticed that the links in that directory didn't get updated during an JDK installation update. So it's best to remove C:\ProgramData\Oracle\Java\javapath; from the Path system environment variable in order to have a consistent environment.
其他回答
Java 11的Java路径设置
复制jdk-11的路径
不要包含\bin文件夹,只包含JDK路径。例如
正确答案是C:\Program Files\Java\jdk-11
错,是C:\Program Files\Java\jdk-11\bin
在环境变量中,用户变量部分单击新建按钮并给出如下路径。
然后给它一个ok,然后进入系统变量,选择路径,双击它。
点击新建,粘贴%JAVA_HOME%\bin,然后点击确定全部。
Windows 7用户:
右键单击“我的电脑”,选择“属性”;先进的;系统设置;先进的;环境变量。然后在第二个框中找到PATH并设置如下图所示的变量。
Windows:
Right click on 'My Computers' and open 'Properties'. In Windows Vista or Windows 7, go to "Advanced System Settings". Else go to next step. Go to 'Advanced Tab' and click on Environment Variables button. Select 'Path' under the list of 'System Variables', and press Edit and add C:\Program Files\java\jdk\bin after a semicolon. Now click on 'new' button under system variables and enter 'JAVA_HOME' as variable name and path to jdk home directory (ex. 'C:\Program Files\Java\jdk1.6.0_24' if you are installing java version 6. Directory name may change with diff. java versions) as variable_value.
Linux下:http://lowfatlinux.com/linux-environment-variables.html
当然,你可以使用以下方法从Java中检索它们:
String variable = System.getProperty("mykey");
在编程环境中,您可以执行SET命令(SET classpath=c:\java)或右键单击您的计算机>属性>高级>环境变量。
在批处理文件中可以使用
SET classpath=c:\java
java c:\myapplication.class
推荐文章
- 在流中使用Java 8 foreach循环移动到下一项
- 访问限制:'Application'类型不是API(必需库rt.jar的限制)
- 用Java计算两个日期之间的天数
- 如何配置slf4j-simple
- 在Jar文件中运行类
- 带参数的可运行?
- 我如何得到一个字符串的前n个字符而不检查大小或出界?
- 我可以在Java中设置enum起始值吗?
- Java中的回调函数
- c#和Java中的泛型有什么不同?和模板在c++ ?
- 在Java中,流相对于循环的优势是什么?
- Jersey在未找到InjectionManagerFactory时停止工作
- 在Java流是peek真的只是调试?
- Recyclerview不调用onCreateViewHolder
- 将JSON字符串转换为HashMap