I develop with Eclipse and I want to embed the JRuby scripting engine in
my
application. I have an issue with accented characters and JRuby.
I initialize my engine like this:
ScriptEngineManager m = new ScriptEngineManager();
ScriptEngine rubyEngine = m.getEngineByName(“jruby”);
ScriptContext context = rubyEngine.getContext();
Then I try something really simple:
context.setAttribute(“label”, “à bientôt”, ScriptContext.ENGINE_SCOPE);
Then when I do puts $label
I get this:
à bientôt
I read everywhere that JRuby uses UTF-8 so why does it output my String
like
that?
Is there something special I should do?
Anybody can help me?
Then I try something really simple:
context.setAttribute(“label”, “à bientôt”, ScriptContext.ENGINE_SCOPE);
Then when I do puts $label
I get this:
à bientôt
Did you check your project’s text file encoding setting? This setting
is in a “Resource” section of project’s properties window.
The encoding you used to save the file and the one Eclipse used to
compile must be the same. My blog entry, yokolet's notelets: Why did I get "??????" ?, might help
you.
I read everywhere that JRuby uses UTF-8 so why does it output my String like
that?
JRuby uses platfrom default encoding if you don’t use Ruby 1.9’s m17n
feature, while JRuby engine can handle any Java supported encoding.
However, the file and compilation encoding mismatch causes
incorrect-output troubles.