[√]windows java 版本管理

527 阅读2分钟

JEnv-for-Windows

  1. git clone github.com/FelixSelter…

  2. 将这个目录添加的环境变量,方便命令行执行jenv.bat

  3. 命令行执行jenv,会提示需要管理员权限将jenv.bat所在的目录放在PATH最前边

    image.png

  4. jenv不会自动下载所需要的java,仅仅是对本地版本的管理,先添加: jenv add <name> <path>

    比如xxx/java/bin/java.exe,对应的:jenv add java1.8 xxx/javabin/java.exe会自动补全,并检查是否存在

  5. 通过name使用java版本:jenv use <name>

  6. 通过java -version验证

jenv local xxx可以为某个目录自动设置某个java版本,没有真正的切换版本,这个设计和其他的多版本管理软件非常不同,非常好的设计

image.png

jenv存在一个问题,只能根据目录配置,不能全局切换

C:\Users\Administrator\Desktop>jenv -h
"jenv list"                            List all registered Java-Envs.
"jenv add <name> <path>"               Adds a new Java-Version to JEnv which can be refferenced by the given name
"jenv remove <name>"                   Removes the specified Java-Version from JEnv
"jenv change <name>"                   Applys the given Java-Version globaly for all restarted shells and this one
"jenv use <name>"                      Applys the given Java-Version locally for the current shell
"jenv local <name>"                    Will use the given Java-Version whenever in this folder. Will set the Java-version for all subfolders as well
"jenv link <executable>"               Creates shortcuts for executables inside JAVA_HOME. For example "javac"
"jenv uninstall <name>"                Deletes JEnv and restores the specified java version to the system. You may keep your config file
"jenv autoscan [--yes|-y] ?<path>?"    Will scan the given path for java installations and ask to add them to JEnv. Path is optional and "--yes|-y" accepts defaults.

android studio切换java版本

我使用的as版本

image.png

Build file 'G:\proj\ndk-samples\other-builds\ndkbuild\hello-jni\app\build.gradle' line: 2

An exception occurred applying plugin request [id: 'com.android.application']
> Failed to apply plugin 'com.android.internal.application'.
   > Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8.
      Your current JDK is located in C:\Program Files\Java\jdk1.8.0_202\jre
      You can try some of the following options:
       - changing the IDE settings.
       - changing the JAVA_HOME environment variable.
       - changing `org.gradle.java.home` in `gradle.properties`.
       - 

File/Project Structure/SDK Location/Gradle Settings

image.png

Gradle JDK列出了本机所有可用的jdk,还支持下载,不用自己苦哈哈的去官网找了

image.png

image.png