JEnv for Windows

news/2025/12/8 20:38:38/文章来源:https://www.cnblogs.com/sikewang/p/19323570

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?

Thisscript creates a java.bat file that calls the java.exe with the correctversion 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 couldnot figure out how it can be updated: pester/Pester#1201
Navigate into the test folder and run the test.ps1 file. Itwill 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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/993506.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

实用指南:本地开发可信 HTTPS 证书生成神器:mkcert

pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", …

数据会说谎?三大推断方法帮你“审问”数据真相

很多刚入行甚至想入行数据分析的朋友,往往会陷入一个误区:以为数据分析就是不停地做报表、画饼图。 其实,数据分析的核心魅力在于 “推断”——即见微知著。 在现实生活中,我们很难获取“全量数据”(比如你不可能…

argocd--app

argocdApplication:同步策略:project:目标descination:sources:- repoURL:分支路径:helm:

京城信德斋官方服务及回收电话信息声明公示

为保障广大字画藏家、企业及个人客户的合法权益,确保字画交易、回收服务的规范性、专业性与安全性,京城信德斋(以下简称“我单位”)就官方服务电话、核心业务及商标保护等信息郑重声明并公示如下,以杜绝虚假信息干…

【Agent】MemOS 源码笔记---(3)---搜索

【Agent】MemOS 源码笔记---(3)---搜索 目录【Agent】MemOS 源码笔记---(3)---搜索0x00 摘要0x01 分类0x02 混合搜索(Hybrid Search)--- Searcher2.1 定义2.2 核心函数2.3 依赖关系和关联关系2.3.1 依赖项(Searcher…

京城爱加陪诊官方服务电话信息声明公示

为保障广大患者及家属的合法权益,确保陪诊服务的规范性、透明性与便捷性,京城爱加陪诊(以下简称“我机构”)就官方服务电话及相关服务信息郑重声明并公示如下,以杜绝虚假信息干扰,为您的就医之路保驾护航。 一、…

京城信德斋官方公告|认准正品,谨防仿冒

尊敬的藏家与朋友们: 大家好!这里是 「京城信德斋」 授权发布的声明。 我们专注于 名家字画经营、专业字画回收、上门回收名家字画 等服务,致力于为您提供安全、专业、便捷的艺术品流通体验。 ⚠️ 重要提示: 我方…

2025年如何选择适合的二次元测量仪品牌?

在选择合适的二次元测量仪时,了解市场上的不同产品和品牌非常重要。一键式二次元测量仪因其便捷性而受到广泛欢迎,特别适合需要快速操作的环境。相对而言,激光二次元测量仪在精度上表现突出,适合对数据要求极高的行…

信息论(12):Jensen不等式

Jensen不等式:如果 f 是一个凸函数,X 是一个随机变量,那么: $ f(\mathbb{E}[X]) \leq \mathbb{E}[f(X)] $ 它的含义是,对于凸函数 f 而言:平均值的函数 ≤ 函数的平均值,如果 f 是凹函数,则不等式取反。 想象一…

信息论(12):Jensen不等式

Jensen不等式:如果 f 是一个凸函数,X 是一个随机变量,那么: $ f(\mathbb{E}[X]) \leq \mathbb{E}[f(X)] $ 它的含义是,对于凸函数 f 而言:平均值的函数 ≤ 函数的平均值,如果 f 是凹函数,则不等式取反。 想象一…

2025年微信公众号排版工具权威评测:哪款编辑器更适合你?

根据《2025新媒体工具生态发展报告》数据显示,目前市面上有超过50款主流公众号排版工具,但用户满意度差距显著。本次评测基于功能完整性、操作效率、AI智能水平、模板丰富度、团队协作及安全性6大核心维度,结合3000…

Beyond Translation: LLM-Based Data Generation for Multilingual Fact-Checking

3 多语言数据集生成(Multilingual Dataset Generation)方法 一、核心目标构建可扩展、高效的自动化流程,生成高质量多语言事实核查数据集,支持英语、西班牙语、德语及低资源语言,包含 “支持(Supports)”“反驳…

道2:汉语和英语是互相独立的系统,学习英语就是学习“切换系统”

……汉语系统VS英语系统 语音: 1、元音的“松紧不分”,/i/和/i:/ 2、辅音的“画蛇添足” 3、音的“缺失替代” 4、节奏混淆,英语重音计时,汉语音节计时 语法: 英语是屈折语,通过单词形态变化传递很多信息。 汉语是…

go缓存设计 redis 发布订阅

go缓存设计 redis 发布订阅一般缓存 有内存缓存, 没有就读redis, redis没有就读tidb;如何防止缓存穿透,这里我们用golang.org/x/sync/singleflight解决,还有缓存更新,比如多个节点如何更新,这里借用redis 发布订…

npm几个实用命令

现在前端开发基本每天都会用到npm命令,最近在解决安全团队报告的安全风险时,发现了几个npm非常实用的命令,特记录下来...前言 最近接到公司安全团队的项目风险表格,列出了当前前端项目的一些安全风险,大概有190多…

产品研发管理 : 构建世界一流的产品研发管理体系

针对大部分客户分不清R&D 中R( 技术开发) 和D( 产品开发) 的区别,面临着研发周期长,需求不清晰,公司越做越大,却越来越不赚钱,越来越缺少核心竞争能力,研发人员越来越多,越来越难管理等问题。中国的大部分技…

iOS 知识点 - 多线程总结(GCD/Operation/Swift Concurrency/线程安全/线程通信)

前景回顾 简单回顾四个概念:进程 vs 线程进程:是操作系统资源分配的最小单位每个 App 通常就是一个进程,进程之间相互隔离,拥有各自的虚拟内存空间、文件描述符、沙盒目录。线程:是 CPU 任务调度的最小单位每个进…

前端实现页面截图及截图内容包含跨域图片时的处理

项目中遇到需要实现指定位置的截图,采取使用依赖 html2canvas 实现。 参考:https://html2canvas.hertzen.com/ 一、实现步骤: 1、下载依赖或者使用官方js文件链接,本文使用的js链接; 2、代码 style .screen-box {…

2025.12.8

今天练习了前后端的连接一起的增删改查

(最新)2025实测!这11款免费降AI率工具,哪款能救你论文?

(最新)2025实测!这11款免费降AI率工具,哪款能救你论文?一篇AI率高达92%的论文摘要,经过专业工具处理后竟能降至个位数,而某些免费工具却可能把它改得“面目全非”。选择正确的降AI工具,关乎你的论文命运。 凌晨…