What is the best way to share gem repository between different JRuby versions?
Recent versions of RubyGems searches $HOME/.gem/jruby/1.8. You can verify this with
jruby -S gem env
and look for GEM PATHS.
Related
I have a Ruby on Rails app that I want to compile/package as a WAR file to host in Tomcat. I've added all of the relevant stuff I can find, but the WAR only appears to include the non-JRuby versions of gems. As a result, I get GemNotFound exceptions such as "could not find activerecord-jdbc-adapter" in Tomcat. If I open the WAR file in 7-zip, it does not show any of the JRuby or Java gems under /WEB-INF/gems/gems.
Warbler does not report any errors or warnings, and the WAR appears to contain everything it needs, except for these gems.
(Because this is a lightweight, internal app, I'm using sqlite for now... which explains the sqlite gems. The DB is stored outside the project and configured in the database.yml file.)
The relevant snippet from my Gemfile:
if defined?(JRUBY_VERSION)
gem 'jdbc-sqlite3'
gem 'activerecord-jdbc-adapter'
gem 'activerecord-jdbcsqlite3-adapter'
gem 'jruby-openssl'
gem 'jruby-rack'
else
gem 'sqlite3'
end
I also tried explicitly including/excluding these gems in the warble.rb file:
config.gems -= ["sqlite3"]
config.gems += [
"jdbc-sqlite3",
"activerecord-jdbc-adapter",
"activerecord-jdbcsqlite3-adapter",
"jruby-openssl",
"jruby-rack",
"warbler"
]
As an interesting side note, if I modify my Gemfile to demand the JRuby gems, jruby -S bundle install works fine but warble gives a series of errors stating that the gems are only for use with JRuby. On the other hand, if I try to run it within JRuby (jruby -S warble) I get:
warble aborted!
no such file to load -- jruby_pageant
How can I convince Warbler that I want the JRuby gems?
Edit:
I also tried specifying platforms in the gemfile, as described in this blog post, but this causes warble to stack-overflow.
platforms :jruby do
gem 'jdbc-sqlite3'
gem 'activerecord-jdbc-adapter', :require => false
gem 'activerecord-jdbcsqlite3-adapter', :require => false
gem 'jruby-openssl'
gem 'jruby-rack'
end
platforms :ruby do
gem 'sqlite3'
end
Versions:
ruby 1.9.3
jruby 1.7.4
warbler 1.3.8
So it turns out that I was missing the jruby-pageant gem. Once I added this to the bundle, jruby -S warble produced the expected output.
I've recently started exploring JRuby using Joe Kutner's book "Deploying with JRuby", but I've hit an issue when trying to install the jruby-lint gem. Below is the output from my attempts, including the version numbers of Java, JRuby, and my OS.
I don't understand the output, especially why nokogiri wouldn't install as a jruby-lint dependency, but would install ok on its own. While the jruby-lint gem is now reported as having installed correctly, it has not delivered a jrlint executable/script to use, and I don't know where to go from here. Any ideas?
C:\Dev\repos\twitalytics>jruby --version
jruby 1.7.3 (1.9.3p385) 2013-02-21 dac429b on Java HotSpot(TM) 64-Bit Server VM 1.7.0_21-b11 [Windows 7-amd64]
C:\Dev\repos\twitalytics>jruby -S gem install jruby-lint
Building native extensions. This could take a while...
ERROR: Error installing jruby-lint:
ERROR: Failed to build gem native extension.
C:/Dev/jruby-1.7.3/bin/jruby.exe extconf.rb
NotImplementedError: C extension support is not enabled. Pass -Xcext.enabled=true to JRuby or set JRUBY_OPTS or modify .jrubyrc to enable.
(root) at C:/Dev/jruby-1.7.3/lib/ruby/shared/mkmf.rb:8
require at org/jruby/RubyKernel.java:1027
(root) at C:/Dev/jruby-1.7.3/lib/ruby/shared/rubygems/custom_require.rb:1
(root) at extconf.rb:5
Gem files will remain installed in C:/Users/Owen/.gem/jruby/1.8/gems/nokogiri-1.6.0.rc1 for inspection.
Results logged to C:/Users/Owen/.gem/jruby/1.8/gems/nokogiri-1.6.0.rc1/ext/nokogiri/gem_make.out
C:\Dev\repos\twitalytics>set JRUBY_OPTS=--1.8
C:\Dev\jruby-1.7.3>jruby --version
jruby 1.7.3 (ruby-1.8.7p370) 2013-02-21 dac429b on Java HotSpot(TM) 64-Bit Server VM 1.7.0_21-b11 [Windows 7-amd64]
C:\Dev\repos\twitalytics>jruby -S gem install jruby-lint
ERROR: Error installing jruby-lint:
nokogiri requires Ruby version >= 1.9.2.
C:\Dev\repos\twitalytics>jruby -S gem install nokogiri
Fetching: nokogiri-1.5.9-java.gem (100%)
Successfully installed nokogiri-1.5.9-java
1 gem installed
C:\Dev\repos\twitalytics>jruby -S gem install jruby-lint
Fetching: jruby-lint-0.4.1.gem (100%)
Successfully installed jruby-lint-0.4.1
1 gem installed
C:\Dev\repos\twitalytics>jrlint
'jrlint' is not recognized as an internal or external command,
operable program or batch file.
I ran into a very similar issue, also while working through this book. Updating Rubygems solved it for me. Perhaps try:
jruby -S gem update --system
It's interesting that it tries to install the Ruby(not JRuby) version of Nokogiri cause it tries to install C extensions.
I think if you install the same version required by jruby-lint which is nokogiri-1.6.0.rc1, problem will be solved.
Neither solution here works for me on Windows. jruby -S gem install nokogiri
installs nokogiri-1.6.0-java
If I download the gem from https://github.com/jruby/jruby-lint and build it myself it leaves the gem folder empty at jruby\lib\ruby\gems\shared\gems\jruby-lint-0.4.1
And it won't make a bat file for running it in the /bin dir. I don't think this gem is ready for windows. Could it be that I'm trying to install it on BitNami stack? I haven't tried it with a regular install of JRuby.
In case updating Rubygems doesn't work, try:
gem install nokogiri
This will install nokogiri-1.6.0-java
then again:
gem install jruby-lint
and you're good to go.
The current Trinidad gem depends on jruby-rack 1.1.0 which has some errors being displayed in my development log for every single one of my assets
/Users/bijan/.rvm/gems/jruby-1.7.3/gems/rack-1.4.5/lib/rack/utils.rb:399 warning: multiple values for a block parameter (2 for 1)
This is an issue that has apparently been resolved in the current jruby-rack (1.2) master branch and I'd like to make trinidad depend on this.
Is there a way to do this from within my Gemfile? Or another simpler solution than forking the Trinidad gem and specifying a different version of jruby-rack (and wishing it works since it may not).
TL;DR - not really. You'll need to build one or both projects or get some help from the jruby-rack team by way of a release. See bottom for build steps.
The current Trinidad versions (1.4.4 and 1.4.5B1 prerelease) use jruby-rack with optimistic versioning (>= 1.1.10 and >= 1.1.13, respectively), so any dependency that satisfies this (say, 1.2.0) would take precedence without touching Trinidad.
Unfortunately, because of how the JAR is packaged, a git: or github: dependency will not work. You would need to build the gem yourself. This is not too bad -- you really just need Maven beyond a working JDK/JRuby setup.
Once jruby-rack is built/released with the changes, will be able to specify a workable version in your Gemfile (assuming it gets versioned 1.2.0):
gem 'jruby-rack', '~> 1.2.0'
gem 'trinidad'
Maybe the jruby-rack team could backport this specific change to the 1.1.13 maintenance line and push a 1.1.13.2 release if it doesn't introduce incompatibility. Or they may be willing to do a prerelease from master.
I haven't tested that things work properly for assets, but building and specifying the local version was relatively easy:
# Assuming mvn is on the path, JRuby is active, and you
# have gem install permissions:
git clone https://github.com/jruby/jruby-rack.git
cd jruby-rack
bundle install
bundle exec rake clean gem SKIP_SPECS=true
gem install --local target/jruby-rack-1.2.0.SNAPSHOT.gem
After this, you can use gem 'jruby-rack', '~> 1.2.0.SNAPSHOT' in your Gemfile to satisfy Trinidad and test whether your problem is resolved.
I'm using capistrano to deploy a rails app, and it uses bundle install --deployment to put the gems in shared/bundle. I've put the appropriate platform :ruby and platform :jruby blocks in my gemfile, my question is if I switch rvm to jruby and then go to my app root directory and do another bundle install --deployment, will that mess with any of the existing gems there and replace them with jruby ones? Will I be able to switch back to mri and run the app like I always have? Will both platform's gems be in there, and then what about gems like nokogiri that have java versions, will that overwrite the mri version? Will I be able to just switch rvm versions and run the app via mri or jruby as I please at that point?
Turns out mri gems are installed in shared/bundle/ruby and jruby gems in /shared/bundle/jruby, so totally safe to switch to jruby, install your gems, and try it out
I used the jruby zip executable to install 1.6.2, but it looks like they have released 1.6.4. How should I migrate from 1.6.2 to 1.6.4, should I have to re-install or is there a different command.
Mostly all you need to do is reinstall gems on the newly-unpacked JRuby (recommended), or migrate your existing gem installs by copying the lib/ruby/gems/* over to the new location. There's no automated update tool for JRuby itself right now.
Unpack new Jruby
export JRUBY_HOME=/path/to/jruby
export PATH=$PATH:$JRUBY_HOME/bin
Maybe even push the above to .bashrc
Add a list of required Gems to your Gemfile.
To reinstall Gems if needed the best way to do it is as follows
Jruby -S gem install bundler
Cd to /path/to/Gemfile
bundle install