1
我有一个小JRuby Sinatra应用程序使用Jieba for JRuby gem来标记中文句子。汉字编码问题 - Heroku
当运行我的本地机器上的应用程序,我没有任何编码问题:
curl --data "text=Ruby China,对!经是国内最权威的 Ruby 社区,拥有国内所有资深的 Ruby 工程师。&key=myKey" http://localhost:9292
# => ["Ruby", "China", "经是", "国内", "权威", "社区", "拥有", "所有", "资深", "工程师"]
然而,当我推应用的Heroku,我有编码问题:
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当输出:
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 [email protected]:secure-wildwood-3084.git
504ab7d..2f4b7c0 master -> master
谢谢你,让我越来越近我认为。正如你所建议的那样,我更改为Ruby 2.0和JRuby 1.7。现在我得到这个输出:'[“Ruby”,“China”,“\\ u6CA1 \\ u9519”,“\\ u8FD9 \\ u91CC”,“\\ u5C31 \\ u662F”,“\\ u793E \\ u533A“,”\\ u76EE \\ u524D“,”\\ u5DF2 \\ u7ECF“,”\\ u56FD \ u5185“,”\\ u6743 \\ u5A01“,”\\ u62E5 \\ u6709“,” \ u5840 \ u6709“,”\\ u8D44 \\ u6DF1“,”\\ u5DE5 \\ u7A0B \\ u5E08“]'还有其他建议吗? – diasks2 2014-10-22 08:39:10