Skip to content

use command doesn't work on PowerShell #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
h4iku opened this issue Apr 2, 2022 · 5 comments · Fixed by #28
Closed

use command doesn't work on PowerShell #27

h4iku opened this issue Apr 2, 2022 · 5 comments · Fixed by #28
Labels
bug Something isn't working

Comments

@h4iku
Copy link
Contributor

h4iku commented Apr 2, 2022

jenv use command using jenv.bat doesn't change the java version for the current session on PowerShell. Using jenv.ps1 works alright.

This is PowerShell 7.2.2 using jenv.bat:

❯ jenv list
All avaible versions of java

name  path
----  ----
jdk8  C:\Program Files\Java\jdk-8.0.322.6-hotspot
jdk11 C:\Program Files\Java\jdk-11.0.14.101-hotspot
jdk17 C:\Program Files\Java\jdk-17.0.2.8-hotspot

All locally specified versions

❯ java -version
openjdk version "11.0.14.1" 2022-02-08
OpenJDK Runtime Environment Temurin-11.0.14.1+1 (build 11.0.14.1+1)
OpenJDK 64-Bit Server VM Temurin-11.0.14.1+1 (build 11.0.14.1+1, mixed mode)

❯ jenv use jdk17
JEnv changed for the current shell session. Careful this overwrites jenv local

❯ java -version
openjdk version "11.0.14.1" 2022-02-08
OpenJDK Runtime Environment Temurin-11.0.14.1+1 (build 11.0.14.1+1)
OpenJDK 64-Bit Server VM Temurin-11.0.14.1+1 (build 11.0.14.1+1, mixed mode)

On cmd, however, it changes the java version but then jenv use remove doesn't revert it:

>java -version
openjdk version "11.0.14.1" 2022-02-08
OpenJDK Runtime Environment Temurin-11.0.14.1+1 (build 11.0.14.1+1)
OpenJDK 64-Bit Server VM Temurin-11.0.14.1+1 (build 11.0.14.1+1, mixed mode)

>jenv use jdk17
JEnv changed for the current shell session. Careful this overwrites jenv local

>java -version
openjdk version "17.0.2" 2022-01-18
OpenJDK Runtime Environment Temurin-17.0.2+8 (build 17.0.2+8)
OpenJDK 64-Bit Server VM Temurin-17.0.2+8 (build 17.0.2+8, mixed mode, sharing)

>jenv use remove
Your session JEnv was unset

>java -version
openjdk version "17.0.2" 2022-01-18
OpenJDK Runtime Environment Temurin-17.0.2+8 (build 17.0.2+8)
OpenJDK 64-Bit Server VM Temurin-17.0.2+8 (build 17.0.2+8, mixed mode, sharing)
@FelixSelter
Copy link
Owner

Thanks. I will look into this tomorrow. I unfortunately have no time today

@FelixSelter FelixSelter added the bug Something isn't working label Apr 2, 2022
@FelixSelter
Copy link
Owner

I think theres no other way to get this working with powershell then calling the ps1 script.

You can even set it manually with $Env:JENVUSE=jdk17 so you dont have to call the script at all, if thats convenient for you.

I can imagine why this issue with "remove" happens on cmd but I need to investigate further tomorrow

@FelixSelter
Copy link
Owner

FelixSelter commented Apr 2, 2022

I fixed the issue with cmd. There's no way to fix it for PowerShell. You either have to call the ps1 script or set the env var manually. Can this be closed now? Thank you for your contribution

@h4iku
Copy link
Contributor Author

h4iku commented Apr 2, 2022

Thank you. The jenv use remove command works now, but jenv use seems to set the string path of jdk as java command:

>jenv use jdk17
JEnv changed for the current shell session. Careful this overwrites jenv local

>java -version
C:\Program Files\Java\jdk-17.0.2.8-hotspot

>java
C:\Program Files\Java\jdk-17.0.2.8-hotspot

>jenv use remove
Your session JEnv was unset

>java -version
openjdk version "11.0.14.1" 2022-02-08
OpenJDK Runtime Environment Temurin-11.0.14.1+1 (build 11.0.14.1+1)
OpenJDK 64-Bit Server VM Temurin-11.0.14.1+1 (build 11.0.14.1+1, mixed mode)

@FelixSelter
Copy link
Owner

Thanks. I added a warning for better distinction as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants