java切换到指定程序,从Java 8切换到Java 11

I have downloaded and installed oraclejdk11 from oracle official site and modified PATH & JAVA_HOME variable in system environment variable on windows

C:\Users\Aviral>javac -version

javac 11.0.1

C:\Users\Aviral>java -version

java version "1.8.0_102"

Java(TM) SE Runtime Environment (build 1.8.0_102-b14)

Java HotSpot(TM) 64-Bit Server VM (build 25.102-b14, mixed mode)

i know that jdk11 do not contain jre but how can i run a java program from cmd in java 11

解决方案

The JDK includes the JRE which you can launch by using the java executable in the bin folder. You use this executable just like any other executable.

When you type java in the command line it is actually shorthand. It searches your PATH until it finds the first matching java executable. If you want to specify a different java executable you can give the absolute path to the executable.

C:\Users\Avril> "C:\Program Files\Java\jdk-11.0.1\bin\java" -jar path\to\file.jar

You may be wondering, if you've set JAVA_HOME and PATH to point to JDK-11, why does java -version still use Java 8?

Take a look at your PATH and you'll likely find something like C:\ProgramData\Oracle\Java\javapath as one of the first entries (see this). This entry was added automatically when you installed Java 8 and points to the Java 8 executables (java, javaw, and javaws). Since it's before your %JAVA_HOME%\bin entry, it takes precedence. However, ...\javapath doesn't contain javac and that's why javac -version used JAVA_HOME (Java 11).

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值