Troubleshooting
From JRubyWiki
Contents |
Cygwin Gotchas
- Add .bat extension to jruby scripts
- If you try to run JRuby on cygwin for Windows and use the commands without the .bat extension it will default to the bourne shell versions. I'm not sure these work properly.
- Example using gems: $JRUBY_HOME/bin/gem.bat install rails -y --no-ri --no-rdoc
Tried this combination out - it really helped! :-) Cheers!
ActiveRecord / JRuby on Rails Gotchas
It is possible, that db:migrate task fails with the message
undefined method `create_database' for class `#<Class:01x1e30857>'
In this case, try to run the migrations with:
jruby -S rake db:migrate SKIP_AR_JDBC_RAKE_REDEFINES=1
You can also just put
ENV['SKIP_AR_JDBC_RAKE_REDEFINES'] = '1'
somewhere in your Rakefile, or in a custom Rakefile in lib/tasks/*.rake.
JNI gotchas
There are two scenarios in which JNI problems occur: [1] when the jar is in jruby 1.1.2's lib, or [2] when the jar is loaded using ruby's "require" statement in jruby < 1.1.
jruby 1.1.2 +
Jruby 1.1.2 changes how it sets up the classpath. Earlier versions merged the CLASSPATH environment variable with all .jar files in JRUBY_HOME/lib and passed them to the JVM via the -classpath option. Jruby 1.1.2 instead passes all .jar files in lib to the JVM via the -Xbootclasspath/a: option, while CLASSPATH is passed using -classpath. Jjar files that use JNI (e.g. sqljdbc.jar) don't work correctly when they're in the boot classpath, so they should not be placed in jruby's lib directory. Instead, they should be loaded with 'require' or by setting the CLASSPATH environment variable.
jruby < 1.1
In older versions of jruby (pre 1.1), loading a jar into multiple jruby runtimes with require can cause problems with JNI. For example, when using MS SQL Server and integrated security in a rails application and if sqljdbc is loaded with a require statement, running jruby -S rake test:units results in the following error:
com.microsoft.sqlserver.jdbc.AuthenticationJNI <clinit> WARNING: Failed to load the sqljdbc_auth.dll
The error message is displayed because sqljdbc.jar is loaded twice, but the OS and/or JVM and/or native library will only allow the native library to be loaded and initialized once. Two ways to work around this problem are:
- Load the jar on the classpath instead of with a
require. This will cause it to be loaded by a different classloader, so the jar file will only be loaded once per process. - Tell jruby to launch other jrubies out-of-proc with
jruby -J-Djruby.launch.inproc=false rest of command. This will cause a second JVM to be launched in therake test:unitsexample above.

