windows中使用jenv管理java多版本

发布时间 2023-12-31 00:27:24作者: 又一岁荣枯

使用管理员模式打开

  1. git clone github.com/FelixSelter…

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

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

https://p6-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/6058580db98b4163a2d5bd50fd2588cc~tplv-k3u1fbpfcp-jj-mark:3024:0:0:0:q75.awebp#?w=959&h=195&s=10617&e=png&b=0c0c0c

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

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

  3. 通过java -version验证

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

https://p9-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/edb159f995a54dc08243bd0286063f0b~tplv-k3u1fbpfcp-jj-mark:3024:0:0:0:q75.awebp#?w=583&h=96&s=2418&e=png&b=0c0c0c

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.