如何通过运行在Tomcat7中的Grails应用程序执行shell命令?

如何通过运行在Tomcat7中的Grails应用程序执行shell命令?,tomcat,grails,groovy,ubuntu-14.04,Tomcat,Grails,Groovy,Ubuntu 14.04,以下代码仅适用于我的开发环境。但是,它会在生产中抛出一个错误(如下所述) 为MeBuilder分类{ def CompileTime(基本路径、课程ID、所需颜色){ def outputCSSFilename=basePath+'themes/'+courseID.toString()+'.css' def tmpFilename=basePath+courseID.toString()+“\u tmp.scss” def sourceFilename=basePath+'theme buil

以下代码仅适用于我的开发环境。但是,它会在生产中抛出一个错误(如下所述)

为MeBuilder分类{
def CompileTime(基本路径、课程ID、所需颜色){
def outputCSSFilename=basePath+'themes/'+courseID.toString()+'.css'
def tmpFilename=basePath+courseID.toString()+“\u tmp.scss”
def sourceFilename=basePath+'theme builder source.scss'
def source=新文件(sourceFilename)
def tmp=新文件(tmpFilename)
def模式=~/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/
def matches=pattern.matcher(desiredColor).matches()
//检查主题路径是否存在
def dir=新文件(基本路径+主题)
如果(!dir.exists())dir.mkdirs()
//验证颜色
如果(!matches)desiredColor='#4F9C91'
//用所需颜色替换占位符颜色
tmp.withWriter{w->
source.eachLine{line->

您可以尝试使用SASS的绝对路径吗?还有一些方法可以在不使用CLI工具的情况下使用SASS(例如,Vaadin附带了SASS编译器(可能不是所有功能))@cfrick,您的建议有效,但我遇到了另一个问题。我无法禁用静态文件的缓存,即使cachingAllowed设置为“false”在我找到的每个上下文标记上。此外,我删除了以前缓存的每个文件,比如/var/lib/tomcat7/conf/Catalina/localhost和/var/lib/tomcat7/work/Catalina/localhost。你已经面对过了吗?
class ThemeBuilder {

  def compileTheme(basePath, courseID, desiredColor) {
    def outputCSSFilename = basePath + 'themes/' + courseID.toString() + '.css'
    def tmpFilename = basePath + courseID.toString() + '_tmp.scss'
    def sourceFilename = basePath + 'theme-builder-source.scss'

    def source = new File(sourceFilename)
    def tmp = new File(tmpFilename)

    def pattern = ~/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/
    def matches = pattern.matcher(desiredColor).matches()

    // Checks existence of the path for themes
    def dir = new File(basePath + 'themes')
    if (! dir.exists()) dir.mkdirs()

    // Validate color
    if (!matches) desiredColor = '#4F9C91'

    // Replace placeholder color with desired color
    tmp.withWriter { w ->
      source.eachLine { line ->
        w << line.replaceAll('brand-primary: #F7DC40', 'brand-primary: ' + desiredColor) + System.getProperty('line.separator')
      }
    }

    // Compilation process
    def cmd = 'sass ' + tmpFilename + ' ' + outputCSSFilename + ' --style compact'
    def result = cmd.execute()
    result.waitFor()

    //////////////// Debugging ////////////////
    // println "Text output: ${ result.text }"
    // println "Return code: ${ result.exitValue() }"
    // println "stderr: ${ result.err.text }"
    // println "stdout: ${ result.in.text }"
    //////////////////////////////////////////

    // Remove tmp file
    tmp.delete()
  }

}
2014-10-22 14:41:28,886 [http-bio-8080-exec-19] ERROR errors.GrailsExceptionResolver  - IOException occurred when processing request: [PUT] /pemaap/course/update
error=2, No such file or directory. Stacktrace follows:
java.io.IOException: error=2, No such file or directory
        at java.lang.UNIXProcess.<init>(UNIXProcess.java:186)
        at java.lang.ProcessImpl.start(ProcessImpl.java:130)
        at java.lang.ProcessBuilder.start(ProcessBuilder.java:1028)
        at java.lang.Runtime.exec(Runtime.java:617)
        at java.lang.Runtime.exec(Runtime.java:450)
        at java.lang.Runtime.exec(Runtime.java:347)
        at br.com.tokenlab.pemaap.ThemeBuilder.compileTheme(ThemeBuilder.groovy:32)