Skip to content

Commit 09c79ab

Browse files
committed
JEnv now filtering any java version from path
1 parent da61e53 commit 09c79ab

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/jenv.ps1

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,11 @@ $javaPaths = (Get-Command java -All | Where-Object { $_.source -ne ((get-item $P
5050
# Only change something when java versions are found
5151
if ($javaPaths.Length -gt 0) {
5252
Write-Host "JEnv is changing your environment variables. This process could take longer but it happens only when a java executable is found in your path"
53-
$userpath = [System.Environment]::GetEnvironmentVariable("PATH", "User").split(";", [System.StringSplitOptions]::RemoveEmptyEntries)
53+
$userPath = [System.Environment]::GetEnvironmentVariable("PATH", "User").split(";", [System.StringSplitOptions]::RemoveEmptyEntries)
5454
# Remove all javas from path
55-
$userPath = ($userPath | Where-Object { !$javaPaths.Contains($_) }) -join ";"
55+
$userPath = ($userPath | Where-Object { !$javaPaths.Contains($_ + "\java.exe") } ) -join ";"
56+
[System.Environment]::SetEnvironmentVariable("PATH", $userPath, [System.EnvironmentVariableTarget]::User) # Set globally
57+
$userPath = ([System.Environment]::GetEnvironmentVariable("PATH", "MACHINE")) + $userPath
5658

5759
$Env:PATH = $userPath # Set for powershell users
5860
Set-Content -path "jenv.path.tmp" -value $userPath # Create temp file so no restart of the active shell is required

0 commit comments

Comments
 (0)