通过groovy/grails检测平台(Window或Linux)
发布时间:2020-12-14 16:38:35 所属栏目:大数据 来源:网络整理
导读:有没有办法检测由Groovy / Grails运行网站的平台(Window / Linux)? 解决方法 System.properties['os.name'] 将返回操作系统的名称,例如“Windows XP”。所以如果你想知道你是否在Windows上运行,你可以这样做: if (System.properties['os.name'].toLowerC
有没有办法检测由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项目)公开了一些布尔常量,提供与上述代码相同的信息,例如。 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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |