How to keep SDK and Java JRE installed and updated in a windows development environment

2

How to maintain a secure, clean and updated java (SDK and JRE) installation of Java on a computer used for software development?

I'm having problems maintaining my development environment, because I have Eclipse IDE and Android Studio installed, as well as some other applications that use java, and today I had a huge problem after an update of Java, the path in the variables Windows started to point to folders that were not the correct ones, and then Eclipse and Android Studio stopped working, then I adjusted it and Tomcat got lost.

    
asked by anonymous 29.04.2015 / 01:24

1 answer

1

I do not know there is any other way of environment variables in a more practical way, I made a script in powershell to automate this process.

Limitations:

  • Your environment variable must be named%
  • Some java installs do not have the install location so they will not be displayed.

clear
write-host "Aguarde..."
[object[]]$r =  (Get-WmiObject win32_product -Filter " name like 'JAVA %'")

$javaHome = "JAVA_HOME"

Write-Host "Valor atual do JAVA_HOME: $env:JAVA_HOME 'n"

$opcao = 0
$itensValidos = @()
foreach($item in $r){
    if($item.InstallLocation -ne $null){
          Write-Host $opcao - $item.Name - $item.InstallLocation
          $itensValidos += $item
          $opcao++
    }
}

$selecionado = Read-Host "'nInforme qual instalação do java será definida em JAVA_HOME"


if($selecionado -lt 0 -or $selecionado -gt $itensValidos.Count -1){
   Write-Host "Opção invalida"
} 

[Environment]::SetEnvironmentVariable($javaHome, $itensValidos[$selecionado].InstallLocation +"lib" , 'Machine')

Running

AlltheinstalledsoftwaresthathaveJAVA_HOMEnamearesearched,thefollowinglinesdisplaythemenuwiththevalidinstallationsofthejava(thosethathavethepathoftheinstallation),aftertherequestismadethepathnameofJAVA_HOMEandfinallythechangeismadewiththeJAVAmethod.

Sources:

Windows PowerShell Tip of the Week

Environment class .net

Get-WmiObject

    
07.05.2015 / 02:03