【问题标题】:Build using Grails application using Gradle using wrong encoding in GSP在 GSP 中使用错误编码使用 Gradle 构建使用 Grails 应用程序
【发布时间】:2016-07-01 12:23:12
【问题描述】:

我有一个 Grails 应用程序,当通过 Gradle 构建脚本构建 WAR 时,视图以错误的编码呈现(即法语字符显示不正确)。

当运行应用程序或直接从 grails 构建时,一切都正确呈现。

所以,具体来说:

Grails - grails war 工作正常

Gradle - gradle grails-war -PgrailsEnv=prod 给出了不正确的编码。

build.gradle 文件:

buildscript {
    repositories {
        jcenter {
            url "http://jcenter.bintray.com/"
        }
        maven  {
            url "http://repo1.maven.org/maven2"
        }
    }
    dependencies {
        classpath 'org.grails:grails-gradle-plugin:2.1.2'
    }
}

apply plugin: 'grails'

version = 1.0

grails {
    grailsVersion = '2.4.3'
    groovyVersion = '2.4.3' 
}

repositories {
    jcenter {
        url "http://jcenter.bintray.com/"
    }   
    grails.central()
}

dependencies {
    bootstrap 'org.grails.plugins:tomcat:7.0.50'
    compile "org.grails.plugins:cache:1.1.7"
    compile "org.grails.plugins:rest:0.8"
    runtime ("org.grails.plugins:hibernate4:4.3.5.5") {
        exclude module: 'xml-apis'
    }
    runtime "org.grails.plugins:database-migration:1.4.0"

    compile fileTree(dir: 'lib', include: '*.jar')
}

感谢您的帮助。

【问题讨论】:

    标签: grails gradle


    【解决方案1】:

    查看mr.haki's post about Gradle encodinganswers for similar question

    要为我们项目中的所有编译任务设置编码属性,我们 可以使用 TaskContainer 上的 withType() 方法查找所有任务 编译类型。然后我们可以在配置中设置编码 关闭:

    compileJava.options.encoding = 'UTF-8'
    
    tasks.withType(Compile) {
        options.encoding = 'UTF-8'
    }
    

    也请查看section Environments in official docs

    【讨论】:

    • 我确实已经查看了这些参考资料,并在您发表评论后重新访问了它们。不幸的是,我继续遇到麻烦。我对您引用的问题发表了评论,因为我的问题似乎确实相关。谢谢。
    【解决方案2】:

    我对 HTML 模板也有同样的问题。

    -Dfile.encoding=UTF-8 添加为 gradle 构建的 JVM 参数解决了模板的问题。

    对于*.gsp 文件,您可以添加

    <%@ page contentType="text/html;charset=UTF-8" %>
    

    到您文件的&lt;head&gt; 部分。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-10-21
      • 2015-10-02
      • 2015-11-12
      • 1970-01-01
      • 2018-08-11
      • 2010-12-22
      • 1970-01-01
      • 2017-11-09
      相关资源
      最近更新 更多