2011-01-14 8 views

Respuesta

50
System.properties['os.name'] 

devolverá el nombre del SO, p. "Windows XP". Así que si quieres averiguar si se está ejecutando en Windows o no, usted podría hacer algo como:

if (System.properties['os.name'].toLowerCase().contains('windows')) { 
    println "it's Windows" 
} else { 
    println "it's not Windows" 
} 

Alternativamente, org.apache.commons.lang.SystemUtils (del proyecto Apache commons-lang) expone algunas constantes booleanas que proporcionan la misma información que la código anterior, por ejemplo

SystemUtils.IS_OS_MAC 
SystemUtils.IS_OS_WINDOWS 
SystemUtils.IS_OS_UNIX 

constantes más específicos como estos también están disponibles

SystemUtils.IS_OS_WINDOWS_2000 
SystemUtils.IS_OS_SOLARIS 
SystemUtils.IS_OS_MAC_OSX 
Cuestiones relacionadas