惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

B
Blog RSS Feed
B
Blog
N
Netflix TechBlog - Medium
量子位
月光博客
月光博客
博客园_首页
博客园 - Franky
酷 壳 – CoolShell
酷 壳 – CoolShell
Last Week in AI
Last Week in AI
T
The Blog of Author Tim Ferriss
Hugging Face - Blog
Hugging Face - Blog
雷峰网
雷峰网
M
MIT News - Artificial intelligence
J
Java Code Geeks
大猫的无限游戏
大猫的无限游戏
D
DataBreaches.Net
腾讯CDC
Engineering at Meta
Engineering at Meta
云风的 BLOG
云风的 BLOG
L
LangChain Blog
GbyAI
GbyAI
IT之家
IT之家
Y
Y Combinator Blog
人人都是产品经理
人人都是产品经理

博客园 - sikewang

Gradle的init.d的init.gradle , init.d的位置 , x.gradle或x.gradle.kts的位置 maven wrapper 介绍及使用详解 Plugin [id: 'org.gradle.kotlin.kotlin-dsl', version: '4.2.1'] was not found in any of the following sources: jenv报错无法加载文件jenv.ps1 Warning! PATH is not properly set up, /Users/i/.rvm/gems/ruby-3.3.0/bin is not at first place.摘抄整理 mac上如何用fvm设置全局Flutter SDK? Inconsistent JVM-target compatibility detected for tasks 'compileDebugJavaWithJavac' (1.8) and 'compileDebugKotlin' (17). fvm Flutter多版本管理安装与常用指令 JVM_XMS 和 java_opts哪种写法对?如何在JVM中设置JVM_XMS和java_opts? Elastic Search 安装部署最全教程(Docker) VMware中Ubuntu配置固定IP 下载Android SDK tools完成Android SDK 安装、配置环境变量 Oracle JDK究竟从哪个版本开始收费? 报红 import 'package:http/http.dart' as http; import 'package:date_format/date_format.dart'; Flutter doctor CSRF攻击与防御 windows查看文件/夹被哪个进程占用以及解除方法 windows上安装nvm-noinstall.zip 修改chrome用户数据的路径
JEnv-for-Windows 安装与使用
sikewang · 2025-12-08 · via 博客园 - sikewang

JEnv for Windows Version 2 is here.

A complete rewrite of V.1

Change your current Java version with 3 words

  • JEnv allows you to change your current JDK Version.
  • This is helpful for testing or if you have projects requiring different versions of java
  • For example you can build a gradle project which requires java8 without changing your environment variables and then switch back to work with java15
  • It's written in cmd and powershell so it can change the environment variables and can run on any Windows-10+.

I hope you enjoy it. Please give me a star if you like my work. Thank you!

Video Demo:

jenv

Installation

  1. Clone this repository
  2. Add it to the path
  3. Run jenv once so the script can do the rest
  4. If your using cmd you need to call the batch file. If you use powershell you should call /src/jenv.ps1
  5. Some reported problems putting JEnv into their C:/Programs folder due to required admin rights
  6. I hope I could help you. Else open an issue

Warning:

Sometimes its necessary to call jenv when entering a new directory with a local jenv specified. This will set your JAVA_HOME for the current shell and ensures that tools like maven work properly

Usage (Note: local overwrites change. use overwrites local)

  1. Add a new Java environment (requires absolute path)
    jenv add <name> <path>
    Example: jenv add jdk15 D:\Programme\Java\jdk-15.0.1

  2. Change your java version for the current session
    jenv use <name>
    Example: jenv use jdk15
    Environment var for scripting:
    ---PowerShell: $ENV:JENVUSE="jdk17"
    ---CMD/BATCH: set "JENVUSE=jdk17"

  3. Clear the java version for the current session
    jenv use remove
    Example: jenv use remove
    Environment var for scripting:
    ---PowerShell: $ENV:JENVUSE=$null
    ---CMD/BATCH: set "JENVUSE="

  4. Change your java version globally
    jenv change <name>
    Example: jenv change jdk15

  5. Always use this java version in this folder
    jenv local <name>
    Example: jenv local jdk15

  6. Clear the java version for this folder
    jenv local remove
    Example: jenv local remove

  7. List all your Java environments
    jenv list
    Example: jenv list

  8. Remove an existing JDK from the JEnv list
    jenv remove <name>
    Example: jenv remove jdk15

  9. Enable the use of javac, javaw or other executables sitting in the java directory
    jenv link <Executable name>
    Example: jenv link javac

  10. Uninstall jenv and automatically restore a Java version of your choice
    jenv uninstall <name>
    Example: jenv uninstall jdk17

  11. Automatically search for java versions to be added
    jenv autoscan [--yes|-y] ?<path>?
    Example: jenv autoscan "C:\Program Files\Java"
    Example: jenv autoscan // Will search entire system Example: jenv autoscan -y "C:\Program Files\Java" // Will accept defaults

How does this work?

This script creates a java.bat file that calls the java.exe with the correct version When the ps script changes env vars they get exported to tmp files and applied by the batch file An additional parameter to the PowerShell script was added. "--output" alias "-o" will create the tmp files for the batch. See images below

SystemEnvironmentVariablesHirachyShell

SystemEnvironmentVariablesHirachyPowerShell PNG

Contributing

If you want to contribute feel free to do so. This is a great repository for beginners as the amount of code is not huge and you can understand how it works pretty easily.
For running tests I suggest you to use the latest version of powershell (pwsh.exe):
https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell-on-windows?view=powershell-7.2
Be careful you have to run it as pwsh and not as powershell
Then you have to install Pester. This is only for tests: Install-Module -Name Pester -Force -SkipPublisherCheck
You could use your already installed powershell as well. However it has an old Pester Module already installed which you can not use and I could not figure out how it can be updated: pester/Pester#1201
Navigate into the test folder and run the test.ps1 file. It will backup your env vars and your jenv config while testing and automatically restore them later. But you should always let the tests finish else your vars and config wont be restored.

问题

1.jenv add jdkxx "C:/Program/.../jdk安装目录" 时,报C:/Program/.../bin/java.exe not found. Your Path is not a valid JAVA_HOME。

  删除旧的JAVA_HOME: 在进行JEnv安装之前,应先清理系统中的

  添加JEnv到系统路径: 将刚克隆的项目路径添加到系统的环境变量

2.安装jenv-for-windows时,报需要验证文件时,请右键-属性 解锁文件即可。