jRuby and Problems with Warbler, RVM, and Tomcat - jruby

I've been having a tough time getting jRuby on Rails 3 deployed on Tomcat 6. I got it to work exactly once.
I modified my database.yaml and Gemfile to check for jRuby, something like this:
if defined?(JRUBY_VERSION)
gem 'jdbc-mysql'
#gem 'jdbc-sqlite3'
gem 'activerecord-jdbc-adapter'
gem 'activerecord-jdbcmysql-adapter'
#gem 'activerecord-jdbcsqlite3-adapter'
gem 'jruby-openssl'
gem 'jruby-rack'
gem 'warbler'
else
gem 'mysql'
gem "mongrel"
gem 'ruby-debug'
end
Some environment settings:
$ rvm -v
rvm 1.0.14
$ jruby -v
jruby 1.5.3 (ruby 1.8.7 patchlevel 249) (2010-09-28 7ca06d7) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_20) [x86_64-java]
When I run jruby -S bundle install everything goes smoothly.
It's when I try to do something like rake db:migrate, jruby -S rake db:migrate or warble that I get 50 DEPRECATION WARNINGs and an eventual stackoverflow.
I solved this issue by deleting the warbler plugin, it did not like the line Warbler::Task.new
Next, I ran warble config to give me a config/warbler.rb file.
And finally, warble to create my .war file. So far so good.
Now I move the .war file to my Tomcat webapps. Everything works fine except for an error:
Oct 10, 2010 1:34:46 AM org.apache.catalina.core.ApplicationContext log
SEVERE: Application Error
org.jruby.rack.RackInitializationException:
http://github.com/plataformatec/devise.git (at master) is not checked out.
Please run 'bundle install'
I solved this problem once and only once by going into my webapps/myapp/WEB-INF and running jruby -S bundle install
It no longer works and I have no idea what is going on.

I believe this can be called a bug in the current version of Warbler. Using git repositories in your Gemfile don't quite get staged properly in the war file and Bundler is still looking for a checked out repository on disk.
A future version of Warbler will probably do something along the lines of bundle --deployment when you create the war file.
For now, to work around, you might have to vendor the devise code.

The current version of warbler (1.3.6) will also exhibit this behavior if you build a war file with warbler war. I've found that building with the following command works:
warbler compiled war
Hopefully future versions will address this more completely.

Related

Warbler does not package Java/JRuby gems?

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.

rails mysql server error "could not find gem"

When I try to run "rails server" on a new project it returns
Could not find gem 'mysql2 (>= 0) X86-mingw32' in any of the gem sources listed in your Gemfile.
Run 'bundle install' to install missing gems.
I ran 'bundle install' but I'm getting the same error.
I already had mysql installed from the xampp package, but my friend helped me install rails so I'm not sure how he configured it. I use Windows Vista.
Try gem install mysql2. It should then work.
I ran into this issue a while back setting up a RoR dev environment on a windows machine. Had to copy the dll to the ruby/bin folder. See the thread from ruby-forum...
http://www.ruby-forum.com/topic/150580
I had a similar issue. For me, I needed to remove the old Gemfile.lock and allow it be re-generated by running bundle update after I added the same version of mysql to the Gemfile that I had installed via "gem install mysql".
This may or may not be the issue you were running in to, but it appears this error message -> "Could not find gem 'mysql'" can be caused for this reason as well.
I had a similar issue, but when trying to gem install mysql2, it would give me a can't find header files for ruby at ... error message.
Running this fixed the issue for me: sudo apt-get install ruby-dev

Jruby openssl circular dependency

I did a fresh install of jruby 1.6.2, and then wanted to install some gems.
I ran this command:
jruby -S gem install cucumber
And got this error message:
JRuby limited openssl loaded. http://jruby.org/openssl
gem install jruby-openssl for full support.
LoadError: OpenSSL::SSL requires the jruby-openssl gem
(root) at /Users/Staffr02/Development/jruby-1.6.2/lib/ruby/site_ruby/shared/jruby/openssl/autoloads/ssl.rb:8
use_ssl= at /Users/Staffr02/Development/jruby-1.6.2/lib/ruby/site_ruby/shared/jruby/openssl/autoloads/ssl.rb:124
connection_for at /Users/Staffr02/Development/jruby-1.6.2/lib/ruby/site_ruby/1.8/rubygems/remote_fetcher.rb:267
request at /Users/Staffr02/Development/jruby-1.6.2/lib/ruby/site_ruby/1.8/rubygems/remote_fetcher.rb:349
open_uri_or_path at /Users/Staffr02/Development/jruby-1.6.2/lib/ruby/site_ruby/1.8/rubygems/remote_fetcher.rb:306
fetch_path at /Users/Staffr02/Development/jruby-1.6.2/lib/ruby/site_ruby/1.8/rubygems/remote_fetcher.rb:181
load_specs at /Users/Staffr02/Development/jruby-1.6.2/lib/ruby/site_ruby/1.8/rubygems/spec_fetcher.rb:251
load_specs at /Users/Staffr02/Development/jruby-1.6.2/lib/ruby/site_ruby/1.8/rubygems/maven_gemify.rb:72
list at /Users/Staffr02/Development/jruby-1.6.2/lib/ruby/site_ruby/1.8/rubygems/spec_fetcher.rb:224
each at org/jruby/RubyArray.java:1602
list at /Users/Staffr02/Development/jruby-1.6.2/lib/ruby/site_ruby/1.8/rubygems/spec_fetcher.rb:220
list at /Users/Staffr02/Development/jruby-1.6.2/lib/ruby/site_ruby/1.8/rubygems/maven_gemify.rb:63
find_matching_with_errors at /Users/Staffr02/Development/jruby-1.6.2/lib/ruby/site_ruby/1.8/rubygems/spec_fetcher.rb:143
find_matching_with_errors at /Users/Staffr02/Development/jruby-1.6.2/lib/ruby/site_ruby/1.8/rubygems/maven_gemify.rb:54
fetch_with_errors at /Users/Staffr02/Development/jruby-1.6.2/lib/ruby/site_ruby/1.8/rubygems/spec_fetcher.rb:83
find_gems_with_sources at /Users/Staffr02/Development/jruby-1.6.2/lib/ruby/site_ruby/1.8/rubygems/dependency_installer.rb:108
find_spec_by_name_and_version at /Users/Staffr02/Development/jruby-1.6.2/lib/ruby/site_ruby/1.8/rubygems/dependency_installer.rb:212
install at /Users/Staffr02/Development/jruby-1.6.2/lib/ruby/site_ruby/1.8/rubygems/dependency_installer.rb:244
execute at /Users/Staffr02/Development/jruby-1.6.2/lib/ruby/site_ruby/1.8/rubygems/commands/install_command.rb:120
each at org/jruby/RubyArray.java:1602
execute at /Users/Staffr02/Development/jruby-1.6.2/lib/ruby/site_ruby/1.8/rubygems/commands/install_command.rb:115
invoke at /Users/Staffr02/Development/jruby-1.6.2/lib/ruby/site_ruby/1.8/rubygems/command.rb:278
process_args at /Users/Staffr02/Development/jruby-1.6.2/lib/ruby/site_ruby/1.8/rubygems/command_manager.rb:133
run at /Users/Staffr02/Development/jruby-1.6.2/lib/ruby/site_ruby/1.8/rubygems/command_manager.rb:103
run at /Users/Staffr02/Development/jruby-1.6.2/lib/ruby/site_ruby/1.8/rubygems/gem_runner.rb:63
(root) at /Users/Staffr02/Development/jruby-1.6.2/bin/gem:21
So then I tried this:
jruby -S gem install jruby-openssl
And I got the same error, which seemed a little odd. I'm running Mac OS 10.6.6.
I did some googling, and couldn't really find anything, except for a page that said this:
However, this breaks programs that use require 'openssl' as a test for whether openssl is available or not. Soap4r is one such program. In order to support this behavior, simply add
require 'jruby/openssl/gem_only'
So I tracked down the file that seemed to have the error (gem_runner.rb) and added the require line in there. I ran jruby -S gem install jruby-openssl again, and got this error:
ERROR: While executing gem ... (NameError)
uninitialized constant Net::HTTP::OpenSSL
Has anyone else had this problem before? I don't understand what I did wrong! Are there some independent openssl settings that I should delete first?
Any guidance would be much appreciated - thanks,
Rebecca

Installing Rails, MySQL, etc. everything goes wrong

I've been struggling with this for a few hours. Everything just stopped working and I can't get it to work anymore. I'm a noob at Ruby, Ruby on Rails and the Terminal in general. This is really frustrating me so I just try to describe my problem as detailed as possible hoping someone can give me a solution.
I'm on Mac OS X Snow Leopard. I couldn't get Rails working at all just now: Could not find gem 'rails' headaches
But after some tries of reinstalling it, it suddenly worked again. But now I just can't get MySQL to work, and it sometimes even breaks the Rails installation again.
This is what I do:
sudo gem uninstall rails
sudo gem uninstall mysql
sudo gem uninstall mysql2
After these commands, I check the installed gems with gem list. No MySQL gem is listed anymore, but I can still see rails (2.3.5, 2.2.2, 1.2.6)
. Is this normal? Does this mean I have 3 Rails installations? It doesn't make sense to me. Anyway, then I do this:
sudo gem clean
Which fails completely. I get a bunch of errors like this:
Attempting to uninstall fcgi-0.8.7
Unable to uninstall fcgi-0.8.7:
Gem::InstallError: cannot uninstall, check gem list -d fcgi
It doesn't uninstall anything. At this point, I try to install everything again. I start with:
sudo gem install rails
Which succeeds (I think):
Successfully installed rails-3.0.3
Successfully installed builder-2.1.2
2 gems installed
Installing ri documentation for rails-3.0.3...
File not found: lib
Then, I update RubyGems:
sudo gem update --system
sudo gem install rubygems-update
sudo update_rubygems
Then it says I have 1.3.7 installed, so it succeeded, I think. So now I proceed with installing MySQL. I already got MySQL 5.5.8 installed on my machine. I did some research about installing MySQL on Snow Leopard, and it seems I have to use this command:
sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
I get a bunch of errors like this:
No definition for time_set_neg
No definition for time_set_second_part
No definition for time_equal
No definition for error_errno
At this point, I assume I got both Rails and the MySQL gem installed, so I try to start a new project.
rails new user_group -d mysql
It works! Rails is installed correctly. Now, I try generating a model.
cd user_group
rails generate model User
It fails with this error:
Could not find gem 'mysql2 (>= 0, runtime)' in any of the gem sources listed in your Gemfile.
Try running bundle install.
So I try running bundle install. It installs a lot of gems. Then I try to generate my model again. I get this error:
Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle: dlopen(/Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle, 9): Library not loaded: libmysqlclient.16.dylib (LoadError)
Referenced from: /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle
Reason: image not found - /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle
This is as far as I can get. What should I do? And why should this be so hard...
Snow Leopard supplies Ruby 1.8.7. Ruby 1.8.7 doesn't automatically add the require 'rubygems' command to a Ruby script, like 1.9.2 will, so in general you need to add that to your script. That fixes the problems with Ruby not finding the gems called by your code in a lot of cases. Rails is a different animal, but the version with 1.8.7 is well documented so you should have found a fix pretty quickly.
The Ruby supplied by Snow Leopard is really for its own use. Users can piggyback on that, but it's installed by Apple because they have applications that use it. Use locate podcast | grep rb$ to see. Similarly, Perl and Python in Snow Leopard are used to support code Apple has installed so messing with them is not a good idea. Changing the built-in Ruby, Perl or Python usually won't cause the system to explode in flames, but it can cause irritating and unexplained problems farther down the road when system maintenance routines stop working.
By using sudo to remove gems installed by Apple and add new ones, you've left your system Ruby in an unexpected state as far as Apple's apps are concerned. Rather than mess with Apple's Ruby, you should install a separate Ruby for your own use using Fink or MacPorts, or from source code, or by using RVM.
Personally, I use RVM because it creates a ~/.rvm sandbox in your home directory, and makes it easy to manage multiple versions of Ruby and gems. RVM requires you to install the XCode development library, which you can download from http://developer.apple.com/technologies/ after a free registration. XCode is also on your system DVD, but that version is reported to be buggy, so use the downloaded version.
Make sure to add the MySql gem to that projects gemfile with the following code:
gem 'mysql', '2.8.1'
Run a bundle install/update and try it. You told it to use MySQL and the gem might even be installed, but you aren't loading it.
Also, you're failing at a couple of points: notice the
File not found: lib
Then again, I could be completely wrong about this - it's my attempt at providing a clue for your troubleshooting.

Rails 3 Mysql Problems

Trying to start a new Rails 3 beta 4 app with mysql.... Running OS X Snow Leopard. WIth previous versions of Rails I have no problem with MySQL. But now when I start the Rails 3 app I get the following error when I click "About Your Application Environment" on the Rails index.html startup screen:
undefined method `init' for Mysql:Class
Change your Gemfile to use 'mysql2', it's a more modern driver and has nicer features as other people have mentioned.
New Rails applications use the mysql2 gem by default.
I ran into the same issue (RoR 3, OSX 10.6, mysql 2.8.1 gem).
You can use irb to rule out RoR:
irb
require 'rubygems'
require 'mysql'
db = Mysql.connect('hostname', 'username', 'password', 'database')
If the above doesn't work, you may want to try removing the mysql gem and reinstalling it. I came across a post saying bundle install might mess up the install without displaying errors.
sudo gem uninstall mysql
sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
Verify things work via irb, then start up rails again.
I ended up switching from the mysql gem to the ruby-mysql gem, worked.
For simple usage, which is typical (connecting, querying, iterating over results), I found mysql2 gem which is much faster than mysql or ruby-mysql gems and auto-casts values to proper types. And it installes perfectly on Snow Leopard while I couldn't get mysql gem to work.
More info at http://github.com/brianmario/mysql2
I think I have found the solution for the problem. In my case the problem was that the mysql gem hasn't been properly installed using the bundler . when I did this:
bundle install mysql (noobish mistake)
all gems went to mysql directory, but later on I have checked the docs of the bundler gem
and did this:
bundle install bundler_files ( to know where the gems are in the future)
everything looked almost ok except that when mysql gem was installing i got some errors.
I noticed that it was because of my folder path "/home/pawel/Aptana Studio Workspace/myrails_app"
If you have spaces in your folder path this gem wont install properly and later on when you modify the path to one without spaces and try to install the mysql gem IT WONT DISPLAY ANY ERRORS, but the installation will be corrupted, because you will have some extra folders there with some files etc. so
DELETE THE GEM FOLDER CREATED BY BUNDLER AND REINSTALL GEMS WITH THIS COMMAND:
bundle install
That solved the problem.
you can try switching to the mysql2 gem which should resolve all that issues for you. see: https://github.com/brianmario/mysql2/
I think what happens is that the mysql gem isn't able to load the mysql dynamic library (supposed to be supplied by the native MySQL installation). To test whether this is happening, do this
$ irb
1.9.2p320 :001 > require 'mysql_api'
=> true
1.9.2p320 :002 >
If it isn't able to load this low level mysql_api, (which actually supplies the functionality to the mysql gem), it will give you some potentially useful errors. Usually it is not able to find the dynamic library. To remedy this, I found a couple of solutions:
From http://wonko.com/post/how-to-install-the-mysqlruby-gem-on-mac-os-x-leopard, do this
For system-wide install
sudo env ARCHFLAGS="-arch i386" gem install mysql -- \
--with-mysql-dir=/usr/local/mysql --with-mysql-lib=/usr/local/mysql/lib \
--with-mysql-include=/usr/local/mysql/include
or local install
env ARCHFLAGS="-arch i386" gem install mysql -- \
--with-mysql-dir=/usr/local/mysql --with-mysql-lib=/usr/local/mysql/lib \
--with-mysql-include=/usr/local/mysql/include
and then from http://alexbraunstein.com/2011/08/12/library-loaded-libmysqlclient-18-dylib/ put in .bash_profile:
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib:$DYLD_LIBRARY_PATH
I has the same issue after upgrading to Snow Leopard. On installing the MySQL gem, I got a bunch of errors about the documentation, then, on running the server:
undefined method `init' for Mysql:Class
I was also having some similar, but unrelated issues with other gems, particularly those that had C components that needed compiling such as RedCloth and hpricot:
Unable to compile native extensions
These errors were to do with native extensions in base 64 architecture. The solution was threefold:
I reinstalled XCode 4. The upgrade to Snow Leopard had broken my C compiler, so some gems were failing to compile. This took me a step closer, but didn't fix the issue.
I blew away and reinstalled RVM. It appeared to be installing gems in one directory, and finding them in another. This fixed every native architecture base64 error, but the MySQL gem was still failing.
I removed and downgraded MySQL to version 5.1. This fixed the MySQL gem issue.
All is now well again.