How do I use JRUBY_OPTS with RVM?

戏子无情 提交于 2019-11-30 02:20:53

this option was parsed with jruby nailgun hook only, i have added a new hook to parse only this options (no ng):

rvm get head
chmod +x ${rvm_path}/hooks/after_use_jruby_opts

and it should work upon entering directory with this option

Allen Rohner

I put export JRUBY_OPTS="..." in my project's .rvmrc, at the bottom of the file. This works for me.

export JRUBY_OPTS="--1.9 -J-XX:+CMSClassUnloadingEnabled -J-XX:+UseConcMarkSweepGC -J-XX:MaxPermSize=256m -J-Xmx1024m"

$ jruby -v
jruby 1.6.5 (ruby-1.9.2-p136) (2011-10-25 9dcd388) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_29) [darwin-x86_64-java]

@mpapis identified the problem and provided the fix. Here's some additional background. TL;DR: use PROJECT_JRUBY_OPTS and the jRuby hooks.

jRuby uses JRUBY_OPTS to configure jRuby's behavior.

RVM supports PROJECT_JRUBY_OPTS with two provided hook files (currently, after_use_jruby and after_use_jruby_opts). If enabled by making them executable, the hooks use the script library functions jruby_options_append and jruby_options_remove to append/remove the options in PROJECT_JRUBY_OPTS to/from JRUBY_OPTS.

So, you have two options.

If you install the latest RVM, you can roll your own per-project .rvmrc, and you can set environment variables and run commands, as you would expect. No additional steps are required.

$ cat >> ~/tmp/.rvmrc
export JRUBY_OPTS='--1.9'
^D

And then:

$ cd ~/tmp
$ env | grep OPTS
JRUBY_OPTS='--1.9'

Or you can enable the jruby hooks, generate an .rvmrc, and customize it:

$ chmod +x ${rvm_path}/hooks/after_use_jruby_opts # or after_use_jruby

Then:

$ cd ~/tmp
$ rvm --rvmrc --create jruby@projectxyz # edit the resulting .rvmrc, uncomment PROJECT_JRUBY_OPTS

And now:

$ cd ~/tmp
$ env | grep OPTS
JRUBY_OPTS='--1.9'

There are subtle differences to the two approaches.

With the first approach, the changes to JRUBY_OPTS persist even if you navigate back out of the project directory. With the second approach, the project-specific options are removed from the JRUBY_OPTS environment variable when you navigate out of the project directory.

Likewise, the first case overwrites JRUBY_OPTS with the value in .rvmrc, while the second case intelligently appends the project-specific information.

@paul-biggar, unfortunately I wasn't able to duplicate the problem where RVM unset JRUBY_OPTS.

Since your are using rvm just create a file .ruby-env in your directory folder. Inside the file you can define your custom env. Like:

JRUBY_OPTS=-Xcext.enabled=true
sushilprj

Add this line to your .bashrc file

export JRUBY_OPTS=--1.9 

It's working fine for me

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!