Java基础知识之Windows环境变量配置
win7和win10的环境变量
Win7系统
Win10系统
windows10环境变量有略小差异,具体操作如下
1.找到我的电脑-属性 文件扩展名选勾
2.点击高级系统属性-环境变量
要先安装软件jdk1.8.0_241.exe
jre的安装可以中断,无需继续安装
确定安装路径为C:\Program Files\Java\jdk1.8.0_241
3.在系统变量中添加变量名:JAVA_HOME值:C:\Program Files\Java\jdk1.8.0_241(根据java版本实际安装目录情况填写)
4.配置好JAVA_HOME后即可配置PATH:%JAVA_HOME%\bin;%JAVA_HOME%\jre\bin;("%"开始和结束代表已在系统变量中配置好的名称)
注意win10是不需要";"间隔,只需要按程序基于新建的值
%JAVA_HOME%\bin
%JAVA_HOME%\jre\bin
即可
5.请确认无误后保存(点击确认即可),JDK1.6及其以上无需配置CLASS_PATH
6.使用JAVA和JAVAC命令测试是否能正常运行JDK
win+r #弹出并输入cmd运行,类似linux中的shell命令
java -version #查看jdk版本
Java基础知识之Linux环境变量配置
下载后解压到指定目录
例如:jdk保存在/home/twoapes/jdk1.8.0_201下
如果需要保存至其他位置,只更换JAVA_HOME目录定义即可
export JAVA_HOME=/home/twoapes/jdk1.8.0_201
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
### 立即生效可以使用:source /etc/profile 如果配置有误,会报错
JDK安装验证
twoapes@twoapes:~$ java ###检查jdk是否能正常使用java命令
Usage: java [-options] class [args...]
(to execute a class)
or java [-options] -jar jarfile [args...]
(to execute a jar file)
where options include:
-d32 use a 32-bit data model if available
-d64 use a 64-bit data model if available
-server to select the "server" VM
The default VM is server,
because you are running on a server-class machine.
-cp <class search path of directories and zip/jar files>
-classpath <class search path of directories and zip/jar files>
A : separated list of directories, JAR archives,
and ZIP archives to search for class files.
-D<name>=<value>
set a system property
-verbose:[class|gc|jni]
enable verbose output
-version print product version and exit
-version:<value>
Warning: this feature is deprecated and will be removed
in a future release.
require the specified version to run
-showversion print product version and continue
-jre-restrict-search | -no-jre-restrict-search
Warning: this feature is deprecated and will be removed
in a future release.
include/exclude user private JREs in the version search
-? -help print this help message
-X print help on non-standard options
-ea[:<packagename>...|:<classname>]
-enableassertions[:<packagename>...|:<classname>]
enable assertions with specified granularity
-da[:<packagename>...|:<classname>]
-disableassertions[:<packagename>...|:<classname>]
disable assertions with specified granularity
-esa | -enablesystemassertions
enable system assertions
-dsa | -disablesystemassertions
disable system assertions
-agentlib:<libname>[=<options>]
load native agent library <libname>, e.g. -agentlib:hprof
see also, -agentlib:jdwp=help and -agentlib:hprof=help
-agentpath:<pathname>[=<options>]
load native agent library by full pathname
-javaagent:<jarpath>[=<options>]
load Java programming language agent, see java.lang.instrument
-splash:<imagepath>
show splash screen with specified image
See http://www.oracle.com/technetwork/java/javase/documentation/index.html for more details.
twoapes@twoapes:~$ javac ###检查jdk是否能正常编译java文件,并且正常使用此命令
Usage: javac <options> <source files>
where possible options include:
-g Generate all debugging info
-g:none Generate no debugging info
-g:{lines,vars,source} Generate only some debugging info
-nowarn Generate no warnings
-verbose Output messages about what the compiler is doing
-deprecation Output source locations where deprecated APIs are used
-classpath <path> Specify where to find user class files and annotation processors
-cp <path> Specify where to find user class files and annotation processors
-sourcepath <path> Specify where to find input source files
-bootclasspath <path> Override location of bootstrap class files
-extdirs <dirs> Override location of installed extensions
-endorseddirs <dirs> Override location of endorsed standards path
-proc:{none,only} Control whether annotation processing and/or compilation is done.
-processor <class1>[,<class2>,<class3>...] Names of the annotation processors to run; bypasses default discovery process
-processorpath <path> Specify where to find annotation processors
-parameters Generate metadata for reflection on method parameters
-d <directory> Specify where to place generated class files
-s <directory> Specify where to place generated source files
-h <directory> Specify where to place generated native header files
-implicit:{none,class} Specify whether or not to generate class files for implicitly referenced files
-encoding <encoding> Specify character encoding used by source files
-source <release> Provide source compatibility with specified release
-target <release> Generate class files for specific VM version
-profile <profile> Check that API used is available in the specified profile
-version Version information
-help Print a synopsis of standard options
-Akey[=value] Options to pass to annotation processors
-X Print a synopsis of nonstandard options
-J<flag> Pass <flag> directly to the runtime system
-Werror Terminate compilation if warnings occur
@<filename> Read options and filenames from file
twoapes@twoapes:~$ java -vsersion ###检查版本号是否和安装前一致
Unrecognized option: -vsersion
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
twoapes@twoapes:~$ java -version
java version "1.8.0_212"
Java(TM) SE Runtime Environment (build 1.8.0_212-b10)
Java HotSpot(TM) 64-Bit Server VM (build 25.212-b10, mixed mode)
twoapes@twoapes:~$