Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ruby ENV variables differing from Java ENV variables (Rails) #2760

Closed
nguyent opened this issue Mar 25, 2015 · 2 comments
Closed

Ruby ENV variables differing from Java ENV variables (Rails) #2760

nguyent opened this issue Mar 25, 2015 · 2 comments

Comments

@nguyent
Copy link

nguyent commented Mar 25, 2015

I have a rails app adding an environment variable in one of the initializers like so:

ENV['TZ'] = 'UTC'

When I start the application the ENV variable appears in Ruby, but not in the Java module.

without passing in ENV variable

$ rvm list
=> jruby-1.7.13 [ x86_64 ]

$ bundle exec rails c
pry(main)> Java::java.lang.System.getenv['TZ']
=> nil
pry(main)> ENV['TZ']
=> "UTC"
pry(main)> ENV.keys - Java::java.lang.System.getenv.keys
=> ["BUNDLE_ORIG_MANPATH", "TZ"]

passing in ENV variable

$ rvm list
=> jruby-1.7.13 [ x86_64 ]

$ TZ=UTC bundle exec rails c
pry(main)> Java::java.lang.System.getenv['TZ']
=> "UTC"
pry(main)> ENV['TZ']
=> "UTC"
pry(main)> ENV.keys - Java::java.lang.System.getenv.keys
=> ["BUNDLE_ORIG_MANPATH"]

I found this ticket here: https://jira.codehaus.org/browse/JRUBY-1579 , but it still seems to be an unresolved issue. I saw Jay's comment about the inability to promote ENV variables from inside the JRuby process, and wanted to know if this is still the case.

If so, it might be easier to have capistrano supply the ENV variable, but it would be nice to be able to do this in code.

@mkristian
Copy link
Member

the code snippet looks OK to me.

I am quite sure that you can not change environment variables java sees via java.lang.System.getenv

then JVM can run several JRuby runtimes. suppose one runtime sets ENV['TZ'] = 'UTC' and the other sets ENV['TZ'] = 'GMT' and both runtimes uses the underlying java.lang.System.getenv

@nguyent
Copy link
Author

nguyent commented Mar 26, 2015

That makes sense, thanks for responding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants