grails - 通过Groovy/Grails检测平台(Window或Linux)

标签 grails groovy platform-detection

有没有办法检测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

关于grails - 通过Groovy/Grails检测平台(Window或Linux),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4689240/

相关文章:

grails - 为 grails 配置 graylog2

grails - Apache2 反向代理,为什么我的解决方案与示例不匹配?

grails - 以编程方式呈现 GSP

groovy - 需要 Groovy 语法帮助从字符串生成闭包

java - 检测 Windows 还是 Linux?

grails - 评估表达式 : Cannot invoke method getAt() on null object 时出错

grails - 如何在GSP中从我的Groovy类使用此get方法

grails - 为什么在保存时两次调用Grails中的二传手?

python - 在 Python 中可靠地检测 Windows