Reputation: 2142
I have a small JRuby Sinatra app that uses the Jieba for JRuby gem to tokenize a Chinese sentence.
When running the app on my local machine I do not have any encoding issues:
curl --data "text=Ruby China,对!经是国内最权威的 Ruby 社区,拥有国内所有资深的 Ruby 工程师。&key=myKey" http://localhost:9292
# => ["Ruby", "China", "经是", "国内", "权威", "社区", "拥有", "所有", "资深", "工程师"]
However, when I push the app to Heroku, I am having encoding issues:
curl --data "text=Ruby China,对!经是国内最权威的 Ruby 社区,拥有国内所有资深的 Ruby 工程师。&key=XWtrws324FGH675BV" http://secure-wildwood-3084.herokuapp.com
# => ["\"Ruby\", \"China\", \" \", \" 。\""]
I've tried to force the encoding to UTF-8 .force_encoding("utf-8")
but still have the issue. I have also tried setting the LANG config variable on Heroku to LANG: zh_CN.UTF-8
but that does not make a difference.
The method I use to deploy the app is in the README. This is the output when pushing the app to 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
Upvotes: 1
Views: 358
Reputation: 7166
looking at the output/project it seems to be using fairly old JRuby bits and pieces, in this case what matters most is the JRuby version (you probably do have a different one locally): 1.6.7 https://github.com/diasks2/jieba-heroku/blob/master/pom.xml#L14
I would bring that to JRuby 1.7.16 and bundle update others from the following output as well :
[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
Upvotes: 1