有没有办法检测Groovy / Grails在其中运行网站的平台(Window / Linux)?
请您参考如下方法:
System.properties['os.name']
将返回操作系统的名称,例如“Windows XP”。因此,如果您想弄清楚您是否在Windows上运行,可以执行以下操作:
if (System.properties['os.name'].toLowerCase().contains('windows')) {
println "it's Windows"
} else {
println "it's not Windows"
}
或者,
org.apache.commons.lang.SystemUtils
(来自
Apache commons-lang项目)公开一些 bool(boolean) 常量,它们提供与上述代码相同的信息,例如
SystemUtils.IS_OS_MAC
SystemUtils.IS_OS_WINDOWS
SystemUtils.IS_OS_UNIX
也可以使用诸如此类的更具体的常量
SystemUtils.IS_OS_WINDOWS_2000
SystemUtils.IS_OS_SOLARIS
SystemUtils.IS_OS_MAC_OSX