首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >汉字编码问题- Heroku

汉字编码问题- Heroku
EN

Stack Overflow用户
提问于 2014-10-22 08:29:13
回答 1查看 298关注 0票数 1

我有一个使用Jieba for JRuby gem对中文句子进行标记化的小型JRuby Sinatra应用程序。

在我的本地机器上运行应用程序时,我没有任何编码问题:

代码语言:javascript
复制
curl --data "text=Ruby China,对!经是国内最权威的 Ruby 社区,拥有国内所有资深的 Ruby 工程师。&key=myKey" http://localhost:9292
# => ["Ruby", "China", "经是", "国内", "权威", "社区", "拥有", "所有", "资深", "工程师"]

然而,当我将应用程序推送到Heroku时,我遇到了编码问题:

代码语言:javascript
复制
curl --data "text=Ruby China,对!经是国内最权威的 Ruby 社区,拥有国内所有资深的 Ruby 工程师。&key=XWtrws324FGH675BV" http://secure-wildwood-3084.herokuapp.com
# => ["\"Ruby\", \"China\", \"  \", \" 。\""]

我尝试强制将编码转换为UTF-8 .force_encoding("utf-8")格式,但仍然有问题。我还尝试将Heroku上的LANG配置变量设置为LANG: zh_CN.UTF-8,但这没有什么区别。

我用来部署应用程序的方法是在README中。这是将应用推送到Heroku时的输出:

代码语言:javascript
复制
Delta compression using up to 8 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 292 bytes | 0 bytes/s, done.
Total 3 (delta 2), reused 0 (delta 0)
-----> Fetching custom git buildpack... done
-----> Java app detected
-----> Installing OpenJDK 1.6... done
-----> executing /app/tmp/cache/.maven/bin/mvn -B -Duser.home=/tmp/build_bfb3b1dc-701f-4558-8560-9617ff535adf -Dmaven.repo.local=/app/tmp/cache/.m2/repository  -DskipTests=true clean install
   [INFO] Scanning for projects...
   [INFO]
   [INFO] ------------------------------------------------------------------------
   [INFO] Building sinatra-jruby-heroku 1.0
   [INFO] ------------------------------------------------------------------------
   [INFO]
   [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ jruby-heroku ---
   [INFO]
   [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ jruby-heroku ---
   [INFO] Using 'UTF-8' encoding to copy filtered resources.
   [INFO] skip non existing resourceDirectory /tmp/build_bfb3b1dc-701f-4558-8560-9617ff535adf/src/main/resources
   [INFO]
   [INFO] --- jruby-rake-plugin:1.6.7:jruby (install-bundler) @ jruby-heroku ---
   [INFO] Successfully installed bundler-1.7.3
   [INFO] 1 gem installed
   [INFO]
   [INFO] --- jruby-rake-plugin:1.6.7:jruby (bundle-install) @ jruby-heroku ---
   [WARNING] JRuby limited openssl loaded. http://jruby.org/openssl
   [WARNING] gem install jruby-openssl for full support.
   [INFO] Fetching gem metadata from http://rubygems.org/..........
   [INFO] Rubygems 1.8.15 is not threadsafe, so your gems must be installed one at a time. Upgrade to Rubygems 2.0.7 or higher to enable parallel gem installation.
   [INFO] Installing jieba-jruby 0.0.1
   [INFO] Installing jruby-rack 1.1.4
   [INFO] Installing json 1.8.0
   [INFO] Installing rack 1.4.1
   [INFO] Installing rack-protection 1.2.0
   [INFO] Installing tilt 1.3.3
   [INFO] Installing sinatra 1.3.2
   [INFO] Installing trinidad_jars 1.0.2
   [INFO] Installing trinidad 1.3.4
   [INFO] Using bundler 1.7.3
   [INFO] Your bundle is complete!
   [INFO] Gems in the groups development and test were not installed.
   [INFO] It was installed into ./vendor/bundle
   [INFO]
   [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ jruby-heroku ---
   [INFO] No sources to compile
   [INFO]
   [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ jruby-heroku ---
   [INFO] Using 'UTF-8' encoding to copy filtered resources.
   [INFO] skip non existing resourceDirectory /tmp/build_bfb3b1dc-701f-4558-8560-9617ff535adf/src/test/resources
   [INFO]
   [INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ jruby-heroku ---
   [INFO] No sources to compile
   [INFO]
   [INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ jruby-heroku ---
   [INFO] Tests are skipped.
   [INFO]
   [INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ jruby-heroku ---
   [WARNING] JAR will be empty - no content was marked for inclusion!
   [INFO] Building jar: /tmp/build_bfb3b1dc-701f-4558-8560-9617ff535adf/target/jruby-heroku-1.0.jar
   [INFO]
   [INFO] --- maven-dependency-plugin:2.3:copy (default) @ jruby-heroku ---
   [INFO] Configured Artifact: org.jruby:jruby-complete:1.6.7:jar
   [INFO] Copying jruby-complete-1.6.7.jar to /tmp/build_bfb3b1dc-701f-4558-8560-9617ff535adf/target/dependency/jruby-complete.jar
   [INFO]
   [INFO] --- maven-install-plugin:2.4:install (default-install) @ jruby-heroku ---
   [INFO] Installing /tmp/build_bfb3b1dc-701f-4558-8560-9617ff535adf/target/jruby-heroku-1.0.jar to /app/tmp/cache/.m2/repository/br/com/tomasmuller/jruby-heroku/1.0/jruby-heroku-1.0.jar
   [INFO] Installing /tmp/build_bfb3b1dc-701f-4558-8560-9617ff535adf/pom.xml to /app/tmp/cache/.m2/repository/br/com/tomasmuller/jruby-heroku/1.0/jruby-heroku-1.0.pom
   [INFO] ------------------------------------------------------------------------
   [INFO] BUILD SUCCESS
   [INFO] ------------------------------------------------------------------------
   [INFO] Total time: 38.742 s
   [INFO] Finished at: 2014-10-17T22:39:20+00:00
   [INFO] Final Memory: 11M/513M
   [INFO] ------------------------------------------------------------------------
 -----> Discovering process types
   Procfile declares types -> console, jruby, rake, web
 -----> Compressing... done, 72.2MB
 -----> Launching... done, v20
   http://secure-wildwood-3084.herokuapp.com/ deployed to Heroku
 To git@heroku.com:secure-wildwood-3084.git
 504ab7d..2f4b7c0  master -> master
EN

回答 1

Stack Overflow用户

发布于 2014-10-22 13:25:12

看一下输出/项目,它似乎使用了相当旧的JRuby片段,在这种情况下,最重要的是JRuby版本(您可能在本地有一个不同的版本):1.6.7 https://github.com/diasks2/jieba-heroku/blob/master/pom.xml#L14

我将把它带到JRuby 1.7.16,并从以下输出中捆绑更新其他内容:

代码语言:javascript
复制
[INFO] Installing jruby-rack 1.1.4
[INFO] Installing json 1.8.0
[INFO] Installing rack 1.4.1
[INFO] Installing rack-protection 1.2.0
[INFO] Installing tilt 1.3.3
[INFO] Installing sinatra 1.3.2
[INFO] Installing trinidad_jars 1.0.2
[INFO] Installing trinidad 1.3.4
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26498572

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档