<?xml version="1.0" encoding="UTF-8"?>
<page>
  <created-at type="datetime">2008-08-12T20:40:41Z</created-at>
  <description>Added comment about JRE and server option on windows under troubleshooting</description>
  <id type="integer">167</id>
  <name>FAQs</name>
  <number type="integer">21</number>
  <person-id type="integer">17486</person-id>
  <text>[[Home|&amp;raquo; JRuby Project Wiki Home Page]]
&lt;h1&gt;JRuby Frequently Asked Questions (FAQs)&lt;/h1&gt;

__TOC__
==Execution Environments==
====Can I run JRuby on Java Micro Edition?====
Somewhat.  See [[JRubyOnJavaMicroEdition|JRuby on JME]].

====How can I run JRuby using Java Web Start?====
Here is a page dedicated to answering this question: [[JRuby on Web Start]]

====How can I make my Ruby scripts execute with JRuby on unix systems like other scripts?====
Include a &quot;hash bang&quot; line on the top of your jruby script like this:
 #!/usr/bin/env jruby
That will use the system wide installed jruby interpreter to run your script.

If you would like to use a local copy of JRuby to run your script, give the relative or absolute path to the jruby program:
 #!/usr/bin/env jruby-1.1RC2/bin/jruby

To run the script directly, you need to set the &quot;x&quot; flag on it:
 chmod +x your_script.rb

You can now start your script with 
 ./your_script.rb

==General==
====Where can I find more information about the Ruby language?====
[http://www.ruby-lang.org The Ruby Language Home Page] has links to a wide range of resources for learning about Ruby, downloading releases of the C implementation of Ruby, documentation on Ruby, and community outlets for talking about Ruby.

[http://www.pragmaticprogrammer.com/ The Pragmatic Programmers] are the publishers of the de facto standard Ruby text, &quot;Programming Ruby&quot;. It is considered a must-have manual to the Ruby language and libraries.

Almost everything you learn about the Ruby language is directly applicable to working with JRuby. JRuby aims to be a drop-in replacement for the C implementation of Ruby.

====What incompatibilities does JRuby have with the C implementation of Ruby? ====
See [[DifferencesBetweenMriAndJruby|Differences Between MRI and JRuby]].

====How do I run JRuby without the command-line scripts?====
Frequently users want to run JRuby from NetBeans, from Eclipse, launched from an existing Java application, or in other ways that don't use the command-line scripts. In addition to having &lt;tt&gt;jruby.jar&lt;/tt&gt; and its dependency jars available in CLASSPATH, you must also have the following system property set:
 jruby.home=''path-to-root-of-JRuby-installation''

You might also want to ensure the maximum memory is set higher than the JVM default. JRuby's own command-line scripts use a maximum of 256MB.

====What if I want to use JRuby alongside C Ruby?  How do I keep from getting confused?====
You have two options:
* Always invoke JRuby with e.g., &lt;tt&gt;jruby -S gem&lt;/tt&gt;.
* Put a handy bash snippet like this in your .bashrc to create &lt;tt&gt;j&lt;/tt&gt; aliases to all the available commands (&lt;tt&gt;rails&lt;/tt&gt; becomes &lt;tt&gt;jrails&lt;/tt&gt;, &lt;tt&gt;rake&lt;/tt&gt; becomes &lt;tt&gt;jrake&lt;/tt&gt;, etc.)
    for f in $JRUBY_HOME/bin/*; do
      f=$(basename $f)
      case $f in jruby*|jirb*|*.bat|*.rb|_*) continue ;; esac
      eval &quot;alias j$f='jruby -S $f'&quot;
    done

====Why can't JRuby find my installed gems?====
JRuby can only see the gems installed with the gem command shipped with JRuby. The gems installed this way will be stored under &lt;tt&gt;$JRUBY_HOME/lib/ruby&lt;/tt&gt;. If you try to run Rails and get the error, &quot;Cannot find gem for Rails ~&gt;1.2.2.0:&quot; (or whatever version you are using), the problem is probably that you haven't installed the Rails-gem and its dependencies with the JRuby gem-command.

====When I implement a Java interface and provide my own initialize method, I can't construct it anymore.====
In JRuby 0.9.0, any class implementing a Java interface must explicitly call &lt;tt&gt;super&lt;/tt&gt; in their initializers to set up the interface proxy. Add a &lt;tt&gt;super&lt;/tt&gt; call to your implementation's &lt;tt&gt;initialize&lt;/tt&gt; method and it should work.

====How do I call JRuby from my existing Java program?====
If you don't want to launch JRuby as a separate process, we recommend you use the [http://jakarta.apache.org/bsf/ Bean Scripting Framework] (BSF) or [https://scripting.dev.java.net/ Java 6's Scripting Support] (JSR223). We do not recommend calling directly into the JRuby runtime, since that code is subject to change.

==== Where can I find the javadoc? ====


====Why do I get a NoSuchMethodError when running JRuby 0.9.0?====
Some users will see the following error when running JRuby 0.9.0:

 Exception in thread &quot;main&quot; java.lang.NoSuchMethodError:
    java.lang.StringBuffer.append(Ljava/lang/CharSequence;)Ljava/lang/StringBuffer;
       at org.jruby.RubyString.cat(RubyString.java:223)
       at org.jruby.RubyString.append(RubyString.java:508)
       at org.jruby.RubyString.concat(RubyString.java:518) 

This error occurs when JRuby is built under Java 5 or higher and run on Java 1.4. Java 5 has the &lt;tt&gt;append(CharSequence)&lt;/tt&gt; method, so it uses that during compilation. Java 1.4 does not have that method.

The first release of JRuby 0.9.0 was mistakenly build with Java 5, so we released a second version compiled with Java 1.4. Make sure you're using a JRuby compiled with Java 1.4 if that's the version of Java you intend to run it under.

====How do I get a Ruby backtrace when calling JRuby code from Java?====
You need to do something along the lines of:

   try {
     rubyCode.doSomething();
   } catch (RaiseException e) {
     e.getException().printBacktrace(System.err);
   }

Note that Java 6's scripting via the BSF libraries might not preserve stack traces, and also launches more slowly.  It's often preferable (as of February 2007) to use JRuby's own integration.

====Why do I get a &lt;tt&gt;java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.visit()&lt;/tt&gt; error when running JRuby 1.X with a custom classpath?====
The problem stems from an ASM jar conflict. It was found by setting a custom classpath, which includes a version of Spring that has a conflicting ASM jar, and then invoking JRuby. The easiest workaround is to build &lt;tt&gt;jruby-complete&lt;/tt&gt; as a single jar and edit the JRuby config file (not sure about Windows, but it should be similar) to source only the &lt;tt&gt;jruby-complete&lt;/tt&gt; jar. You will need to add ALL other jars, which I  believe includes your jdbc driver as well.

  svn co &lt;nowiki&gt;http://svn.codehaus.org/jruby/tags/jruby-1_0/&lt;/nowiki&gt;
  cd jruby-1_0
  ant jar-complete
  vi bin/jruby (see diff for edit)
    #diff bin/jruby bin/jruby.orig 
    #89c89
    #&lt;     for j in &quot;$JRUBY_HOME&quot;/lib/jruby-complete.jar; do
    #---
    #&gt;     for j in &quot;$JRUBY_HOME&quot;/lib/*.jar; do

====How come Java can't find resources in class folders that I've appended to the $CLASSPATH global variable at runtime? ====
JRubyClassLoader extends &lt;tt&gt;java.net.URLClassLoader&lt;/tt&gt;, which treats any URL that doesn't end with a slash as a jar. See [http://java.sun.com/j2se/1.5.0/docs/api/java/net/URLClassLoader.html URLClassLoader].

====Why don't my special characters (like &#231;&#227;o) appear correctly in my Swing app ?====
The file encoding for the &lt;tt&gt;.rb&lt;/tt&gt; file containing the special characters must be set to UTF-8. There were also issues in versions of JRuby before 1.2 where unicode characters were not properly pulled out via the &lt;tt&gt;toString&lt;/tt&gt; method on Ruby objects. Try upgrading to 1.2 or higher.

====Under OSX I get this error when trying to execute jruby:  &quot;Exception in thread 'main' java.lang.NoClassDefFoundError: org/jruby/Main&quot; ====
The source of this problem is the inclusion of &lt;tt&gt;'.'&lt;/tt&gt; (current directory) in your $PATH. You're also trying to execute JRuby from &lt;tt&gt;$JRUBY_HOME/bin&lt;/tt&gt;. There's a bug in the JRuby bash script that prevents this from working.

To correct the issue, remove &lt;tt&gt;'.'&lt;/tt&gt; from your $PATH and relaunch the shell. Alternately, if you really want to keep &lt;tt&gt;'.'&lt;/tt&gt; in your $PATH (which you shouldn't, but see google for reasons why), then just change your working directory to something other than &lt;tt&gt;$JRUBY_HOME/bin&lt;/tt&gt; and execute the &lt;tt&gt;jruby&lt;/tt&gt; command. It should launch just fine.
  % cd /any/path/other/than/jruby_home
  % jruby # should work

'''Note:'''' This bug has been fixed in JRuby 1.2.

====How do I check which version of the JVM JRuby is running on?====
  % jruby -rjava -e &quot;puts java.lang.System.get_property('java.version')&quot;

==Running Rails==
====Why does script/server (WEBrick) terminate right after saying &quot;Booting WEBrick...&quot;?====
This happens if you require ActiveRecord-JDBC in your environment, but you haven't installed the gem. Make sure you have the ActiveRecord-JDBC gem installed.

====How do I avoid installing the Rails gem twice for both CRuby and JRuby?====
You just need to set GEM_HOME to point to your CRuby's gem directory.  For example, in tcsh:
 setenv GEM_HOME /usr/local/lib/ruby/gems/1.8

Note that on Windows, you should specify the path using unix-style directory separators. For example, if ruby is installed in &lt;tt&gt;C:\ruby&lt;/tt&gt;:
 set GEM_HOME=c:/ruby/lib/ruby/gems/1.8

====I get the error &quot;undefined method 'cattr_accessor' for ActiveRecord::Base:Class (NoMethodError)&quot; after configuring activerecord-jdbc.  What is wrong?====
You're not requiring activerecord-jdbc properly. Try requiring activerecord-jdbc in &lt;tt&gt;config/environment.rb&lt;/tt&gt; this way:
 require 'jdbc_adapter'

====I keep getting &quot;500.html running rails app built by goldspike in a JEE Container&quot;. What is wrong?====
You might not have set the production DB settings in &lt;tt&gt;database.yml&lt;/tt&gt; properly. Goldspike by default builds a war that runs the app in production mode. 

You can confirm the problem by finding the &lt;tt&gt;production.log&lt;/tt&gt; file. If you're using JBoss, then it lives in &lt;tt&gt;$JBOSS_HOME/server/my_app/tmp/my_rails_war&lt;/tt&gt;''1234''&lt;tt&gt;.war&lt;/tt&gt;, where ''1234'' is a random number generated by JBoss.

In &lt;tt&gt;production.log&lt;/tt&gt;, you'll see an error this:
 RuntimeError (The driver encountered an error: can't convert nil into String)

To fix this, just set the production DB settings in &lt;tt&gt;database.yml&lt;/tt&gt; properly.

====How can I load a ResourceBundle from the Rails config directory ?====
You can add the config directory to the JRuby classpath in &lt;tt&gt;config/environment.rb&lt;/tt&gt;:
  $CLASSPATH &lt;&lt; &quot;file:///#{File.expand_path(File.join(RAILS_ROOT, 'config'))}/&quot;

Now, because &lt;tt&gt;ResourceBundle.getBundle&lt;/tt&gt; doesn't seem to use the JRuby class loader, we need to pass it explicitly. In the file where you want to use the resource bundle do :
  include Java
  require 'jruby'
  ...
  bundle = java.util.ResourceBundle::getBundle
     (&quot;i18n&quot;, java.util.Locale::FRENCH, JRuby.runtime.j_ruby_class_loader)

Now you just need to put your &lt;tt&gt;i18n[_*].properties&lt;/tt&gt; files in &lt;tt&gt;config/&lt;/tt&gt;, et voil&#224;!

==Calling Into Java==

====Why do I get &lt;tt&gt;ClassNotFoundException&lt;/tt&gt; when I call &lt;tt&gt;java.lang.Class.forName&lt;/tt&gt; from Ruby?====
When JRuby runs at the command line, it loads into the bootstrap class loader. This class loader lives above CLASSPATH, so libraries you add to CLASSPATH are not normally visible. Because &lt;tt&gt;Class.forName&lt;/tt&gt; uses the class loader of the nearest non-system class that called it, it ends up seeing JRuby as the caller and looking for classes only in CLASSPATH.

The workaround for this is simple: Uuse JRuby's import or include_class methods to load the class, or just reference it directly as in &lt;tt&gt;Java::my.package.MyClass&lt;/tt&gt; or &lt;tt&gt;org.postgresql.Driver&lt;/tt&gt;.

====How do I access an inner class with a lowercase name?====
Sometimes, developers name their inner classes beginning with a lowercase letter. This prevents JRuby from accessing it the &quot;normal way&quot; (it thinks it's a method). For example:

In Java (from the &lt;tt&gt;com.sun.enterprise.ee.cms.core&lt;/tt&gt; package of the [https://shoal.dev.java.net/ Shoal project])

 GMSConstants.shutdownType.INSTANCE_SHUTDOWN

Whereas in JRuby, you can get at that using the following:

 &gt;&gt; ShutdownType = JavaUtilities.get_proxy_class(
          'com.sun.enterprise.ee.cms.core.GMSConstants$shutdownType')

==Java and JRuby Interoperation==

==== How do I create a primitive Java array in JRuby?====
You can convert existing ruby arrays to primitive Java arrays very simply:

 [1,2,3].to_java =&gt; makes an object array
 [1,2,3].to_java :byte =&gt; makes a byte array
 [1,2,3].to_java :String =&gt; makes a String array

To create empty arrays:

 Java::byte[12].new =&gt; makes a new byte[]
 java.lang.String[12].new =&gt; makes a new String[]

====How can I implement a Java Interface using a Ruby Class?====
There are two separate ways:

* Include an interface into the class.
   class MyListener
     include java.awt.event.ActionListener
 
     def actionPerformed(event)
       button.text = &quot;I have been pressed&quot;
     end
   end

* Use implicit closure conversion.
   button.add_action_listener { |event|  button.text = &quot;I have been pressed&quot; }

== Compiler-related questions==

====How can I compile my Ruby into Java?====
You can do an Ahead-Of-Time (AOT) compile by using these [[JRubyCompiler|instructions]].

== Troubleshooting==

==== Why do my ruby scripts under cygwin get executed as if they are bourne shell scripts?====
Add &lt;tt&gt;.bat&lt;/tt&gt; extension to JRuby scripts.

If you try to run JRuby on cygwin for Windows and use the commands without the &lt;tt&gt;.bat&lt;/tt&gt; extension, it will default to the bourne shell versions, which might not work properly.

'''Example using gems:'''
 $JRUBY_HOME/bin/gem.bat install rails -y --no-ri --no-rdoc

==== Why does my db:migrate fail with &quot;undefined method 'create_database' for class '#&lt;Class:01x1e30857&gt;'&quot;?====
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 the following line somewhere in your Rakefile, or in a custom Rakefile in &lt;tt&gt;lib/tasks/*.rake&lt;/tt&gt;:
 ENV['SKIP_AR_JDBC_RAKE_REDEFINES'] = '1'

&lt;span id=&quot;troubleshooting_JNI&quot;&gt;&lt;/span&gt;
==== I am having a weird JNI problem. Help me!====
There are two scenarios in which JNI problems occur: 
* When the jar is in JRuby 1.1.2's lib.
* When the jar is loaded using ruby's &quot;require&quot; statement in JRuby &lt; 1.1.
These two scenarios are described below.

===== JRuby 1.1.2 + =====
JRuby 1.1.2 changed how it set up the classpath. Earlier versions merged the CLASSPATH environment variable with all .jar files in &lt;tt&gt;JRUBY_HOME/lib&lt;/tt&gt; and passed them to the JVM via the &lt;tt&gt;-classpath&lt;/tt&gt; option. JRuby 1.1.2 instead passes all &lt;tt&gt;.jar&lt;/tt&gt; files in &lt;tt&gt;lib&lt;/tt&gt; to the JVM via the &lt;tt&gt;-Xbootclasspath/a:&lt;/tt&gt; option, while CLASSPATH is passed using &lt;tt&gt;-classpath&lt;/tt&gt;. Jar files that use JNI (e.g. &lt;tt&gt;sqljdbc.jar&lt;/tt&gt;) don't work correctly when they're in the boot classpath, so they should not be placed in JRuby's &lt;tt&gt;lib&lt;/tt&gt; directory. Instead, they should be loaded with &lt;tt&gt;require&lt;/tt&gt; or by setting the CLASSPATH environment variable.

===== JRuby &lt; 1.1 =====
In older versions of JRuby (pre 1.1), loading a jar into multiple JRuby runtimes with &lt;tt&gt;require&lt;/tt&gt; can cause problems with JNI. For example, when using Microsoft SQL Server and integrated security in a rails application with &lt;tt&gt;sqljdbc&lt;/tt&gt; loaded with a &lt;tt&gt;require&lt;/tt&gt; statement, running &lt;tt&gt;jruby&lt;/tt&gt; &lt;tt&gt;-S&lt;/tt&gt; &lt;tt&gt;rake&lt;/tt&gt; &lt;tt&gt;test:units&lt;/tt&gt; results in the following error:
 com.microsoft.sqlserver.jdbc.AuthenticationJNI
 &amp;lt;clinit&amp;gt;
 WARNING: Failed to load the sqljdbc_auth.dll

The error message is displayed because &lt;tt&gt;sqljdbc.jar&lt;/tt&gt; 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. There are two ways to work around this problem.

* Load the jar on the classpath instead of using &lt;tt&gt;require&lt;/tt&gt;. This will cause it to be loaded by a different class loader, so the jar file will only be loaded once per process.
* Tell JRuby to launch other jrubies out-of-proc with &lt;br/&gt;&lt;tt&gt;jruby '''-J-Djruby.launch.inproc=false''' ''rest of command''&lt;/tt&gt;&lt;br/&gt; This will cause a second JVM to be launched in the &lt;tt&gt;rake&lt;/tt&gt; &lt;tt&gt;test:units&lt;/tt&gt; example above.

==== I tried the --server option and received an error====
You tried the performance tuning option --server but received an error like &quot;Error: no `server' JVM at `c:\Program Files\Java\jre6\bin\server\jvm.dll'.&quot;
On windows the Java Runtime Environment (JRE) does not include the server VM. You should download an install the Java Development Kit (JDK). 
If you want to use the server with the JRE, you can copy JDK's jre\bin\server folder to a bin\server directory in the Java SE Runtime Environment.</text>
  <text-as-html>&lt;p&gt;&lt;a href='&lt;?url_for_page Home?&gt;' class='internal'&gt;&amp;raquo; JRuby Project Wiki Home Page&lt;/a&gt;&lt;h1&gt;JRuby Frequently Asked Questions (FAQs)&lt;/h1&gt;

&lt;/p&gt;&lt;div id='toc' class='toc'&gt;
           &lt;div id='toctitle' class='toc-title'&gt;
             &lt;span&gt;Contents&lt;/span&gt;
           &lt;/div&gt;
           &lt;div id='toccontents' class='toc-contents'&gt;&lt;ul&gt;&lt;ul&gt;&lt;li&gt;1 &lt;a href='#Execution_Environments'&gt;Execution Environments&lt;/a&gt;&lt;/li&gt;
&lt;ul&gt;&lt;ul&gt;&lt;li&gt;1.1 &lt;a href='#Can_I_run_JRuby_on_Java_Micro_Edition?'&gt;Can I run JRuby on Java Micro Edition?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;1.2 &lt;a href='#How_can_I_run_JRuby_using_Java_Web_Start?'&gt;How can I run JRuby using Java Web Start?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;1.3 &lt;a href='#How_can_I_make_my_Ruby_scripts_execute_with_JRuby_on_unix_systems_like_other_scripts?'&gt;How can I make my Ruby scripts execute with JRuby on unix systems like other scripts?&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/ul&gt;&lt;li&gt;2 &lt;a href='#General'&gt;General&lt;/a&gt;&lt;/li&gt;
&lt;ul&gt;&lt;ul&gt;&lt;li&gt;2.1 &lt;a href='#Where_can_I_find_more_information_about_the_Ruby_language?'&gt;Where can I find more information about the Ruby language?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;2.2 &lt;a href='#What_incompatibilities_does_JRuby_have_with_the_C_implementation_of_Ruby?'&gt;What incompatibilities does JRuby have with the C implementation of Ruby? &lt;/a&gt;&lt;/li&gt;
&lt;li&gt;2.3 &lt;a href='#How_do_I_run_JRuby_without_the_command-line_scripts?'&gt;How do I run JRuby without the command-line scripts?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;2.4 &lt;a href='#What_if_I_want_to_use_JRuby_alongside_C_Ruby?_How_do_I_keep_from_getting_confused?'&gt;What if I want to use JRuby alongside C Ruby?  How do I keep from getting confused?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;2.5 &lt;a href='#Why_can_t_JRuby_find_my_installed_gems?'&gt;Why can't JRuby find my installed gems?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;2.6 &lt;a href='#When_I_implement_a_Java_interface_and_provide_my_own_initialize_method,_I_can_t_construct_it_anymore.'&gt;When I implement a Java interface and provide my own initialize method, I can't construct it anymore.&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;2.7 &lt;a href='#How_do_I_call_JRuby_from_my_existing_Java_program?'&gt;How do I call JRuby from my existing Java program?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;2.8 &lt;a href='#Where_can_I_find_the_javadoc?'&gt; Where can I find the javadoc? &lt;/a&gt;&lt;/li&gt;
&lt;li&gt;2.9 &lt;a href='#Why_do_I_get_a_NoSuchMethodError_when_running_JRuby_0.9.0?'&gt;Why do I get a NoSuchMethodError when running JRuby 0.9.0?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;2.10 &lt;a href='#How_do_I_get_a_Ruby_backtrace_when_calling_JRuby_code_from_Java?'&gt;How do I get a Ruby backtrace when calling JRuby code from Java?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;2.11 &lt;a href='#Why_do_I_get_a_java.lang.NoSuchMethodError:_org.objectweb.asm.ClassWriter.visit()_error_when_running_JRuby_1.X_with_a_custom_classpath?'&gt;Why do I get a &lt;tt&gt;java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.visit()&lt;/tt&gt; error when running JRuby 1.X with a custom classpath?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;2.12 &lt;a href='#How_come_Java_can_t_find_resources_in_class_folders_that_I_ve_appended_to_the_$CLASSPATH_global_variable_at_runtime?'&gt;How come Java can't find resources in class folders that I've appended to the $CLASSPATH global variable at runtime? &lt;/a&gt;&lt;/li&gt;
&lt;li&gt;2.13 &lt;a href='#Why_don_t_my_special_characters_(like_&#231;&#227;o)_appear_correctly_in_my_Swing_app_?'&gt;Why don't my special characters (like &#231;&#227;o) appear correctly in my Swing app ?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;2.14 &lt;a href='#Under_OSX_I_get_this_error_when_trying_to_execute_jruby:_&amp;quot;Exception_in_thread__main__java.lang.NoClassDefFoundError:_org/jruby/Main&amp;quot;'&gt;Under OSX I get this error when trying to execute jruby:  &amp;quot;Exception in thread 'main' java.lang.NoClassDefFoundError: org/jruby/Main&amp;quot; &lt;/a&gt;&lt;/li&gt;
&lt;li&gt;2.15 &lt;a href='#How_do_I_check_which_version_of_the_JVM_JRuby_is_running_on?'&gt;How do I check which version of the JVM JRuby is running on?&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/ul&gt;&lt;li&gt;3 &lt;a href='#Running_Rails'&gt;Running Rails&lt;/a&gt;&lt;/li&gt;
&lt;ul&gt;&lt;ul&gt;&lt;li&gt;3.1 &lt;a href='#Why_does_script/server_(WEBrick)_terminate_right_after_saying_&amp;quot;Booting_WEBrick...&amp;quot;?'&gt;Why does script/server (WEBrick) terminate right after saying &amp;quot;Booting WEBrick...&amp;quot;?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;3.2 &lt;a href='#How_do_I_avoid_installing_the_Rails_gem_twice_for_both_CRuby_and_JRuby?'&gt;How do I avoid installing the Rails gem twice for both CRuby and JRuby?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;3.3 &lt;a href='#I_get_the_error_&amp;quot;undefined_method__cattr_accessor__for_ActiveRecord::Base:Class_(NoMethodError)&amp;quot;_after_configuring_activerecord-jdbc._What_is_wrong?'&gt;I get the error &amp;quot;undefined method 'cattr_accessor' for ActiveRecord::Base:Class (NoMethodError)&amp;quot; after configuring activerecord-jdbc.  What is wrong?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;3.4 &lt;a href='#I_keep_getting_&amp;quot;500.html_running_rails_app_built_by_goldspike_in_a_JEE_Container&amp;quot;._What_is_wrong?'&gt;I keep getting &amp;quot;500.html running rails app built by goldspike in a JEE Container&amp;quot;. What is wrong?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;3.5 &lt;a href='#How_can_I_load_a_ResourceBundle_from_the_Rails_config_directory_?'&gt;How can I load a ResourceBundle from the Rails config directory ?&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/ul&gt;&lt;li&gt;4 &lt;a href='#Calling_Into_Java'&gt;Calling Into Java&lt;/a&gt;&lt;/li&gt;
&lt;ul&gt;&lt;ul&gt;&lt;li&gt;4.1 &lt;a href='#Why_do_I_get_ClassNotFoundException_when_I_call_java.lang.Class.forName_from_Ruby?'&gt;Why do I get &lt;tt&gt;ClassNotFoundException&lt;/tt&gt; when I call &lt;tt&gt;java.lang.Class.forName&lt;/tt&gt; from Ruby?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;4.2 &lt;a href='#How_do_I_access_an_inner_class_with_a_lowercase_name?'&gt;How do I access an inner class with a lowercase name?&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/ul&gt;&lt;li&gt;5 &lt;a href='#Java_and_JRuby_Interoperation'&gt;Java and JRuby Interoperation&lt;/a&gt;&lt;/li&gt;
&lt;ul&gt;&lt;ul&gt;&lt;li&gt;5.1 &lt;a href='#How_do_I_create_a_primitive_Java_array_in_JRuby?'&gt; How do I create a primitive Java array in JRuby?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;5.2 &lt;a href='#How_can_I_implement_a_Java_Interface_using_a_Ruby_Class?'&gt;How can I implement a Java Interface using a Ruby Class?&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/ul&gt;&lt;li&gt;6 &lt;a href='#Compiler-related_questions'&gt; Compiler-related questions&lt;/a&gt;&lt;/li&gt;
&lt;ul&gt;&lt;ul&gt;&lt;li&gt;6.1 &lt;a href='#How_can_I_compile_my_Ruby_into_Java?'&gt;How can I compile my Ruby into Java?&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/ul&gt;&lt;li&gt;7 &lt;a href='#Troubleshooting'&gt; Troubleshooting&lt;/a&gt;&lt;/li&gt;
&lt;ul&gt;&lt;ul&gt;&lt;li&gt;7.1 &lt;a href='#Why_do_my_ruby_scripts_under_cygwin_get_executed_as_if_they_are_bourne_shell_scripts?'&gt; Why do my ruby scripts under cygwin get executed as if they are bourne shell scripts?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;7.2 &lt;a href='#Why_does_my_db:migrate_fail_with_&amp;quot;undefined_method__create_database__for_class__#&amp;lt;Class:01x1e30857&amp;gt;_&amp;quot;?'&gt; Why does my db:migrate fail with &amp;quot;undefined method 'create_database' for class '#&amp;lt;Class:01x1e30857&amp;gt;'&amp;quot;?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;7.3 &lt;a href='#I_am_having_a_weird_JNI_problem._Help_me!'&gt; I am having a weird JNI problem. Help me!&lt;/a&gt;&lt;/li&gt;
&lt;ul&gt;&lt;li&gt;7.3.1 &lt;a href='#JRuby_1.1.2_+'&gt; JRuby 1.1.2 + &lt;/a&gt;&lt;/li&gt;
&lt;li&gt;7.3.2 &lt;a href='#JRuby_&amp;lt;_1.1'&gt; JRuby &amp;lt; 1.1 &lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;li&gt;7.4 &lt;a href='#I_tried_the_--server_option_and_received_an_error'&gt; I tried the --server option and received an error&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/ul&gt;&lt;/ul&gt;&lt;/ul&gt;&lt;/div&gt;
         &lt;/div&gt;&lt;h2&gt;&lt;a name='Execution_Environments'&gt;&lt;/a&gt;Execution Environments&lt;/h2&gt;
&lt;h4&gt;&lt;a name='Can_I_run_JRuby_on_Java_Micro_Edition?'&gt;&lt;/a&gt;Can I run JRuby on Java Micro Edition?&lt;/h4&gt;
&lt;p&gt;Somewhat.  See &lt;a href='&lt;?url_for_page JRubyOnJavaMicroEdition?&gt;' class='internal'&gt;JRuby on JME&lt;/a&gt;.

&lt;/p&gt;&lt;h4&gt;&lt;a name='How_can_I_run_JRuby_using_Java_Web_Start?'&gt;&lt;/a&gt;How can I run JRuby using Java Web Start?&lt;/h4&gt;
&lt;p&gt;Here is a page dedicated to answering this question: &lt;a href='&lt;?url_for_page JRuby on Web Start?&gt;' class='internal'&gt;JRuby on Web Start&lt;/a&gt;

&lt;/p&gt;&lt;h4&gt;&lt;a name='How_can_I_make_my_Ruby_scripts_execute_with_JRuby_on_unix_systems_like_other_scripts?'&gt;&lt;/a&gt;How can I make my Ruby scripts execute with JRuby on unix systems like other scripts?&lt;/h4&gt;
&lt;p&gt;Include a &amp;quot;hash bang&amp;quot; line on the top of your jruby script like this:
&lt;/p&gt;&lt;pre&gt; #!/usr/bin/env jruby
&lt;/pre&gt;&lt;p&gt;That will use the system wide installed jruby interpreter to run your script.

&lt;/p&gt;&lt;p&gt;If you would like to use a local copy of JRuby to run your script, give the relative or absolute path to the jruby program:
&lt;/p&gt;&lt;pre&gt; #!/usr/bin/env jruby-1.1RC2/bin/jruby
&lt;/pre&gt;&lt;p&gt;
To run the script directly, you need to set the &amp;quot;x&amp;quot; flag on it:
&lt;/p&gt;&lt;pre&gt; chmod +x your_script.rb
&lt;/pre&gt;&lt;p&gt;
You can now start your script with 
&lt;/p&gt;&lt;pre&gt; ./your_script.rb
&lt;/pre&gt;&lt;h2&gt;&lt;a name='General'&gt;&lt;/a&gt;General&lt;/h2&gt;
&lt;h4&gt;&lt;a name='Where_can_I_find_more_information_about_the_Ruby_language?'&gt;&lt;/a&gt;Where can I find more information about the Ruby language?&lt;/h4&gt;
&lt;p&gt;&lt;a class='external' href=&quot;http://www.ruby-lang.org&quot;&gt;The Ruby Language Home Page&lt;/a&gt; has links to a wide range of resources for learning about Ruby, downloading releases of the C implementation of Ruby, documentation on Ruby, and community outlets for talking about Ruby.

&lt;/p&gt;&lt;p&gt;&lt;a class='external' href=&quot;http://www.pragmaticprogrammer.com/&quot;&gt;The Pragmatic Programmers&lt;/a&gt; are the publishers of the de facto standard Ruby text, &amp;quot;Programming Ruby&amp;quot;. It is considered a must-have manual to the Ruby language and libraries.

&lt;/p&gt;&lt;p&gt;Almost everything you learn about the Ruby language is directly applicable to working with JRuby. JRuby aims to be a drop-in replacement for the C implementation of Ruby.

&lt;/p&gt;&lt;h4&gt;&lt;a name='What_incompatibilities_does_JRuby_have_with_the_C_implementation_of_Ruby?'&gt;&lt;/a&gt;What incompatibilities does JRuby have with the C implementation of Ruby? &lt;/h4&gt;
&lt;p&gt;See &lt;a href='&lt;?url_for_page DifferencesBetweenMriAndJruby?&gt;' class='internal'&gt;Differences Between MRI and JRuby&lt;/a&gt;.

&lt;/p&gt;&lt;h4&gt;&lt;a name='How_do_I_run_JRuby_without_the_command-line_scripts?'&gt;&lt;/a&gt;How do I run JRuby without the command-line scripts?&lt;/h4&gt;
&lt;p&gt;Frequently users want to run JRuby from NetBeans, from Eclipse, launched from an existing Java application, or in other ways that don't use the command-line scripts. In addition to having &lt;tt&gt;jruby.jar&lt;/tt&gt; and its dependency jars available in CLASSPATH, you must also have the following system property set:
&lt;/p&gt;&lt;pre&gt; jruby.home=&lt;i&gt;path-to-root-of-JRuby-installation&lt;/i&gt;
&lt;/pre&gt;&lt;p&gt;
You might also want to ensure the maximum memory is set higher than the JVM default. JRuby's own command-line scripts use a maximum of 256MB.

&lt;/p&gt;&lt;h4&gt;&lt;a name='What_if_I_want_to_use_JRuby_alongside_C_Ruby?_How_do_I_keep_from_getting_confused?'&gt;&lt;/a&gt;What if I want to use JRuby alongside C Ruby?  How do I keep from getting confused?&lt;/h4&gt;
&lt;p&gt;You have two options:
&lt;/p&gt;&lt;ul&gt;&lt;li&gt; Always invoke JRuby with e.g., &lt;tt&gt;jruby -S gem&lt;/tt&gt;.
&lt;/li&gt;&lt;li&gt; Put a handy bash snippet like this in your .bashrc to create &lt;tt&gt;j&lt;/tt&gt; aliases to all the available commands (&lt;tt&gt;rails&lt;/tt&gt; becomes &lt;tt&gt;jrails&lt;/tt&gt;, &lt;tt&gt;rake&lt;/tt&gt; becomes &lt;tt&gt;jrake&lt;/tt&gt;, etc.)
&lt;/li&gt;&lt;/ul&gt;&lt;pre&gt;    for f in $JRUBY_HOME/bin/*; do
      f=$(basename $f)
      case $f in jruby*|jirb*|*.bat|*.rb|_*) continue ;; esac
      eval &amp;quot;alias j$f='jruby -S $f'&amp;quot;
    done
&lt;/pre&gt;&lt;h4&gt;&lt;a name='Why_can_t_JRuby_find_my_installed_gems?'&gt;&lt;/a&gt;Why can't JRuby find my installed gems?&lt;/h4&gt;
&lt;p&gt;JRuby can only see the gems installed with the gem command shipped with JRuby. The gems installed this way will be stored under &lt;tt&gt;$JRUBY_HOME/lib/ruby&lt;/tt&gt;. If you try to run Rails and get the error, &amp;quot;Cannot find gem for Rails ~&amp;gt;1.2.2.0:&amp;quot; (or whatever version you are using), the problem is probably that you haven't installed the Rails-gem and its dependencies with the JRuby gem-command.

&lt;/p&gt;&lt;h4&gt;&lt;a name='When_I_implement_a_Java_interface_and_provide_my_own_initialize_method,_I_can_t_construct_it_anymore.'&gt;&lt;/a&gt;When I implement a Java interface and provide my own initialize method, I can't construct it anymore.&lt;/h4&gt;
&lt;p&gt;In JRuby 0.9.0, any class implementing a Java interface must explicitly call &lt;tt&gt;super&lt;/tt&gt; in their initializers to set up the interface proxy. Add a &lt;tt&gt;super&lt;/tt&gt; call to your implementation's &lt;tt&gt;initialize&lt;/tt&gt; method and it should work.

&lt;/p&gt;&lt;h4&gt;&lt;a name='How_do_I_call_JRuby_from_my_existing_Java_program?'&gt;&lt;/a&gt;How do I call JRuby from my existing Java program?&lt;/h4&gt;
&lt;p&gt;If you don't want to launch JRuby as a separate process, we recommend you use the &lt;a class='external' href=&quot;http://jakarta.apache.org/bsf/&quot;&gt;Bean Scripting Framework&lt;/a&gt; (BSF) or &lt;a class='external' href=&quot;https://scripting.dev.java.net/&quot;&gt;Java 6's Scripting Support&lt;/a&gt; (JSR223). We do not recommend calling directly into the JRuby runtime, since that code is subject to change.

&lt;/p&gt;&lt;h4&gt;&lt;a name='Where_can_I_find_the_javadoc?'&gt;&lt;/a&gt; Where can I find the javadoc? &lt;/h4&gt;
&lt;p&gt;&lt;br /&gt;

&lt;/p&gt;&lt;h4&gt;&lt;a name='Why_do_I_get_a_NoSuchMethodError_when_running_JRuby_0.9.0?'&gt;&lt;/a&gt;Why do I get a NoSuchMethodError when running JRuby 0.9.0?&lt;/h4&gt;
&lt;p&gt;Some users will see the following error when running JRuby 0.9.0:

&lt;/p&gt;&lt;pre&gt; Exception in thread &amp;quot;main&amp;quot; java.lang.NoSuchMethodError:
    java.lang.StringBuffer.append(Ljava/lang/CharSequence;)Ljava/lang/StringBuffer;
       at org.jruby.RubyString.cat(RubyString.java:223)
       at org.jruby.RubyString.append(RubyString.java:508)
       at org.jruby.RubyString.concat(RubyString.java:518) 
&lt;/pre&gt;&lt;p&gt;
This error occurs when JRuby is built under Java 5 or higher and run on Java 1.4. Java 5 has the &lt;tt&gt;append(CharSequence)&lt;/tt&gt; method, so it uses that during compilation. Java 1.4 does not have that method.

&lt;/p&gt;&lt;p&gt;The first release of JRuby 0.9.0 was mistakenly build with Java 5, so we released a second version compiled with Java 1.4. Make sure you're using a JRuby compiled with Java 1.4 if that's the version of Java you intend to run it under.

&lt;/p&gt;&lt;h4&gt;&lt;a name='How_do_I_get_a_Ruby_backtrace_when_calling_JRuby_code_from_Java?'&gt;&lt;/a&gt;How do I get a Ruby backtrace when calling JRuby code from Java?&lt;/h4&gt;
&lt;p&gt;You need to do something along the lines of:

&lt;/p&gt;&lt;pre&gt;   try {
     rubyCode.doSomething();
   } catch (RaiseException e) {
     e.getException().printBacktrace(System.err);
   }
&lt;/pre&gt;&lt;p&gt;
Note that Java 6's scripting via the BSF libraries might not preserve stack traces, and also launches more slowly.  It's often preferable (as of February 2007) to use JRuby's own integration.

&lt;/p&gt;&lt;h4&gt;&lt;a name='Why_do_I_get_a_java.lang.NoSuchMethodError:_org.objectweb.asm.ClassWriter.visit()_error_when_running_JRuby_1.X_with_a_custom_classpath?'&gt;&lt;/a&gt;Why do I get a &lt;tt&gt;java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.visit()&lt;/tt&gt; error when running JRuby 1.X with a custom classpath?&lt;/h4&gt;
&lt;p&gt;The problem stems from an ASM jar conflict. It was found by setting a custom classpath, which includes a version of Spring that has a conflicting ASM jar, and then invoking JRuby. The easiest workaround is to build &lt;tt&gt;jruby-complete&lt;/tt&gt; as a single jar and edit the JRuby config file (not sure about Windows, but it should be similar) to source only the &lt;tt&gt;jruby-complete&lt;/tt&gt; jar. You will need to add ALL other jars, which I  believe includes your jdbc driver as well.

&lt;/p&gt;&lt;pre&gt;  svn co http://svn.codehaus.org/jruby/tags/jruby-1_0/
  cd jruby-1_0
  ant jar-complete
  vi bin/jruby (see diff for edit)
    #diff bin/jruby bin/jruby.orig 
    #89c89
    #&amp;lt;     for j in &amp;quot;$JRUBY_HOME&amp;quot;/lib/jruby-complete.jar; do
    #---
    #&amp;gt;     for j in &amp;quot;$JRUBY_HOME&amp;quot;/lib/*.jar; do
&lt;/pre&gt;&lt;h4&gt;&lt;a name='How_come_Java_can_t_find_resources_in_class_folders_that_I_ve_appended_to_the_$CLASSPATH_global_variable_at_runtime?'&gt;&lt;/a&gt;How come Java can't find resources in class folders that I've appended to the $CLASSPATH global variable at runtime? &lt;/h4&gt;
&lt;p&gt;JRubyClassLoader extends &lt;tt&gt;java.net.URLClassLoader&lt;/tt&gt;, which treats any URL that doesn't end with a slash as a jar. See &lt;a class='external' href=&quot;http://java.sun.com/j2se/1.5.0/docs/api/java/net/URLClassLoader.html&quot;&gt;URLClassLoader&lt;/a&gt;.

&lt;/p&gt;&lt;h4&gt;&lt;a name='Why_don_t_my_special_characters_(like_&#231;&#227;o)_appear_correctly_in_my_Swing_app_?'&gt;&lt;/a&gt;Why don't my special characters (like &#231;&#227;o) appear correctly in my Swing app ?&lt;/h4&gt;
&lt;p&gt;The file encoding for the &lt;tt&gt;.rb&lt;/tt&gt; file containing the special characters must be set to UTF-8. There were also issues in versions of JRuby before 1.2 where unicode characters were not properly pulled out via the &lt;tt&gt;toString&lt;/tt&gt; method on Ruby objects. Try upgrading to 1.2 or higher.

&lt;/p&gt;&lt;h4&gt;&lt;a name='Under_OSX_I_get_this_error_when_trying_to_execute_jruby:_&amp;quot;Exception_in_thread__main__java.lang.NoClassDefFoundError:_org/jruby/Main&amp;quot;'&gt;&lt;/a&gt;Under OSX I get this error when trying to execute jruby:  &amp;quot;Exception in thread 'main' java.lang.NoClassDefFoundError: org/jruby/Main&amp;quot; &lt;/h4&gt;
&lt;p&gt;The source of this problem is the inclusion of &lt;tt&gt;'.'&lt;/tt&gt; (current directory) in your $PATH. You're also trying to execute JRuby from &lt;tt&gt;$JRUBY_HOME/bin&lt;/tt&gt;. There's a bug in the JRuby bash script that prevents this from working.

&lt;/p&gt;&lt;p&gt;To correct the issue, remove &lt;tt&gt;'.'&lt;/tt&gt; from your $PATH and relaunch the shell. Alternately, if you really want to keep &lt;tt&gt;'.'&lt;/tt&gt; in your $PATH (which you shouldn't, but see google for reasons why), then just change your working directory to something other than &lt;tt&gt;$JRUBY_HOME/bin&lt;/tt&gt; and execute the &lt;tt&gt;jruby&lt;/tt&gt; command. It should launch just fine.
&lt;/p&gt;&lt;pre&gt;  % cd /any/path/other/than/jruby_home
  % jruby # should work
&lt;/pre&gt;&lt;p&gt;&lt;b&gt;Note:&lt;/b&gt;' This bug has been fixed in JRuby 1.2.

&lt;/p&gt;&lt;h4&gt;&lt;a name='How_do_I_check_which_version_of_the_JVM_JRuby_is_running_on?'&gt;&lt;/a&gt;How do I check which version of the JVM JRuby is running on?&lt;/h4&gt;
&lt;pre&gt;  % jruby -rjava -e &amp;quot;puts java.lang.System.get_property('java.version')&amp;quot;
&lt;/pre&gt;&lt;h2&gt;&lt;a name='Running_Rails'&gt;&lt;/a&gt;Running Rails&lt;/h2&gt;
&lt;h4&gt;&lt;a name='Why_does_script/server_(WEBrick)_terminate_right_after_saying_&amp;quot;Booting_WEBrick...&amp;quot;?'&gt;&lt;/a&gt;Why does script/server (WEBrick) terminate right after saying &amp;quot;Booting WEBrick...&amp;quot;?&lt;/h4&gt;
&lt;p&gt;This happens if you require ActiveRecord-JDBC in your environment, but you haven't installed the gem. Make sure you have the ActiveRecord-JDBC gem installed.

&lt;/p&gt;&lt;h4&gt;&lt;a name='How_do_I_avoid_installing_the_Rails_gem_twice_for_both_CRuby_and_JRuby?'&gt;&lt;/a&gt;How do I avoid installing the Rails gem twice for both CRuby and JRuby?&lt;/h4&gt;
&lt;p&gt;You just need to set GEM_HOME to point to your CRuby's gem directory.  For example, in tcsh:
&lt;/p&gt;&lt;pre&gt; setenv GEM_HOME /usr/local/lib/ruby/gems/1.8
&lt;/pre&gt;&lt;p&gt;
Note that on Windows, you should specify the path using unix-style directory separators. For example, if ruby is installed in &lt;tt&gt;C:\ruby&lt;/tt&gt;:
&lt;/p&gt;&lt;pre&gt; set GEM_HOME=c:/ruby/lib/ruby/gems/1.8
&lt;/pre&gt;&lt;h4&gt;&lt;a name='I_get_the_error_&amp;quot;undefined_method__cattr_accessor__for_ActiveRecord::Base:Class_(NoMethodError)&amp;quot;_after_configuring_activerecord-jdbc._What_is_wrong?'&gt;&lt;/a&gt;I get the error &amp;quot;undefined method 'cattr_accessor' for ActiveRecord::Base:Class (NoMethodError)&amp;quot; after configuring activerecord-jdbc.  What is wrong?&lt;/h4&gt;
&lt;p&gt;You're not requiring activerecord-jdbc properly. Try requiring activerecord-jdbc in &lt;tt&gt;config/environment.rb&lt;/tt&gt; this way:
&lt;/p&gt;&lt;pre&gt; require 'jdbc_adapter'
&lt;/pre&gt;&lt;h4&gt;&lt;a name='I_keep_getting_&amp;quot;500.html_running_rails_app_built_by_goldspike_in_a_JEE_Container&amp;quot;._What_is_wrong?'&gt;&lt;/a&gt;I keep getting &amp;quot;500.html running rails app built by goldspike in a JEE Container&amp;quot;. What is wrong?&lt;/h4&gt;
&lt;p&gt;You might not have set the production DB settings in &lt;tt&gt;database.yml&lt;/tt&gt; properly. Goldspike by default builds a war that runs the app in production mode. 

&lt;/p&gt;&lt;p&gt;You can confirm the problem by finding the &lt;tt&gt;production.log&lt;/tt&gt; file. If you're using JBoss, then it lives in &lt;tt&gt;$JBOSS_HOME/server/my_app/tmp/my_rails_war&lt;/tt&gt;&lt;i&gt;1234&lt;/i&gt;&lt;tt&gt;.war&lt;/tt&gt;, where &lt;i&gt;1234&lt;/i&gt; is a random number generated by JBoss.

&lt;/p&gt;&lt;p&gt;In &lt;tt&gt;production.log&lt;/tt&gt;, you'll see an error this:
&lt;/p&gt;&lt;pre&gt; RuntimeError (The driver encountered an error: can't convert nil into String)
&lt;/pre&gt;&lt;p&gt;
To fix this, just set the production DB settings in &lt;tt&gt;database.yml&lt;/tt&gt; properly.

&lt;/p&gt;&lt;h4&gt;&lt;a name='How_can_I_load_a_ResourceBundle_from_the_Rails_config_directory_?'&gt;&lt;/a&gt;How can I load a ResourceBundle from the Rails config directory ?&lt;/h4&gt;
&lt;p&gt;You can add the config directory to the JRuby classpath in &lt;tt&gt;config/environment.rb&lt;/tt&gt;:
&lt;/p&gt;&lt;pre&gt;  $CLASSPATH &amp;lt;&amp;lt; &amp;quot;file:///#{File.expand_path(File.join(RAILS_ROOT, 'config'))}/&amp;quot;
&lt;/pre&gt;&lt;p&gt;
Now, because &lt;tt&gt;ResourceBundle.getBundle&lt;/tt&gt; doesn't seem to use the JRuby class loader, we need to pass it explicitly. In the file where you want to use the resource bundle do :
&lt;/p&gt;&lt;pre&gt;  include Java
  require 'jruby'
  ...
  bundle = java.util.ResourceBundle::getBundle
     (&amp;quot;i18n&amp;quot;, java.util.Locale::FRENCH, JRuby.runtime.j_ruby_class_loader)
&lt;/pre&gt;&lt;p&gt;
Now you just need to put your &lt;tt&gt;i18n[_*].properties&lt;/tt&gt; files in &lt;tt&gt;config/&lt;/tt&gt;, et voil&#224;!

&lt;/p&gt;&lt;h2&gt;&lt;a name='Calling_Into_Java'&gt;&lt;/a&gt;Calling Into Java&lt;/h2&gt;
&lt;h4&gt;&lt;a name='Why_do_I_get_ClassNotFoundException_when_I_call_java.lang.Class.forName_from_Ruby?'&gt;&lt;/a&gt;Why do I get &lt;tt&gt;ClassNotFoundException&lt;/tt&gt; when I call &lt;tt&gt;java.lang.Class.forName&lt;/tt&gt; from Ruby?&lt;/h4&gt;
&lt;p&gt;When JRuby runs at the command line, it loads into the bootstrap class loader. This class loader lives above CLASSPATH, so libraries you add to CLASSPATH are not normally visible. Because &lt;tt&gt;Class.forName&lt;/tt&gt; uses the class loader of the nearest non-system class that called it, it ends up seeing JRuby as the caller and looking for classes only in CLASSPATH.

&lt;/p&gt;&lt;p&gt;The workaround for this is simple: Uuse JRuby's import or include_class methods to load the class, or just reference it directly as in &lt;tt&gt;Java::my.package.MyClass&lt;/tt&gt; or &lt;tt&gt;org.postgresql.Driver&lt;/tt&gt;.

&lt;/p&gt;&lt;h4&gt;&lt;a name='How_do_I_access_an_inner_class_with_a_lowercase_name?'&gt;&lt;/a&gt;How do I access an inner class with a lowercase name?&lt;/h4&gt;
&lt;p&gt;Sometimes, developers name their inner classes beginning with a lowercase letter. This prevents JRuby from accessing it the &amp;quot;normal way&amp;quot; (it thinks it's a method). For example:

&lt;/p&gt;&lt;p&gt;In Java (from the &lt;tt&gt;com.sun.enterprise.ee.cms.core&lt;/tt&gt; package of the &lt;a class='external' href=&quot;https://shoal.dev.java.net/&quot;&gt;Shoal project&lt;/a&gt;)

&lt;/p&gt;&lt;pre&gt; GMSConstants.shutdownType.INSTANCE_SHUTDOWN
&lt;/pre&gt;&lt;p&gt;
Whereas in JRuby, you can get at that using the following:

&lt;/p&gt;&lt;pre&gt; &amp;gt;&amp;gt; ShutdownType = JavaUtilities.get_proxy_class(
          'com.sun.enterprise.ee.cms.core.GMSConstants$shutdownType')
&lt;/pre&gt;&lt;h2&gt;&lt;a name='Java_and_JRuby_Interoperation'&gt;&lt;/a&gt;Java and JRuby Interoperation&lt;/h2&gt;
&lt;h4&gt;&lt;a name='How_do_I_create_a_primitive_Java_array_in_JRuby?'&gt;&lt;/a&gt; How do I create a primitive Java array in JRuby?&lt;/h4&gt;
&lt;p&gt;You can convert existing ruby arrays to primitive Java arrays very simply:

&lt;/p&gt;&lt;pre&gt; [1,2,3].to_java =&amp;gt; makes an object array
 [1,2,3].to_java :byte =&amp;gt; makes a byte array
 [1,2,3].to_java :String =&amp;gt; makes a String array
&lt;/pre&gt;&lt;p&gt;
To create empty arrays:

&lt;/p&gt;&lt;pre&gt; Java::byte[12].new =&amp;gt; makes a new byte[]
 java.lang.String[12].new =&amp;gt; makes a new String[]
&lt;/pre&gt;&lt;h4&gt;&lt;a name='How_can_I_implement_a_Java_Interface_using_a_Ruby_Class?'&gt;&lt;/a&gt;How can I implement a Java Interface using a Ruby Class?&lt;/h4&gt;
&lt;p&gt;There are two separate ways:

&lt;/p&gt;&lt;ul&gt;&lt;li&gt; Include an interface into the class.
&lt;/li&gt;&lt;/ul&gt;&lt;pre&gt;   class MyListener
     include java.awt.event.ActionListener
 
     def actionPerformed(event)
       button.text = &amp;quot;I have been pressed&amp;quot;
     end
   end
&lt;/pre&gt;&lt;ul&gt;&lt;li&gt; Use implicit closure conversion.
&lt;/li&gt;&lt;/ul&gt;&lt;pre&gt;   button.add_action_listener { |event|  button.text = &amp;quot;I have been pressed&amp;quot; }
&lt;/pre&gt;&lt;h2&gt;&lt;a name='Compiler-related_questions'&gt;&lt;/a&gt; Compiler-related questions&lt;/h2&gt;
&lt;h4&gt;&lt;a name='How_can_I_compile_my_Ruby_into_Java?'&gt;&lt;/a&gt;How can I compile my Ruby into Java?&lt;/h4&gt;
&lt;p&gt;You can do an Ahead-Of-Time (AOT) compile by using these &lt;a href='&lt;?url_for_page JRubyCompiler?&gt;' class='internal'&gt;instructions&lt;/a&gt;.

&lt;/p&gt;&lt;h2&gt;&lt;a name='Troubleshooting'&gt;&lt;/a&gt; Troubleshooting&lt;/h2&gt;
&lt;h4&gt;&lt;a name='Why_do_my_ruby_scripts_under_cygwin_get_executed_as_if_they_are_bourne_shell_scripts?'&gt;&lt;/a&gt; Why do my ruby scripts under cygwin get executed as if they are bourne shell scripts?&lt;/h4&gt;
&lt;p&gt;Add &lt;tt&gt;.bat&lt;/tt&gt; extension to JRuby scripts.

&lt;/p&gt;&lt;p&gt;If you try to run JRuby on cygwin for Windows and use the commands without the &lt;tt&gt;.bat&lt;/tt&gt; extension, it will default to the bourne shell versions, which might not work properly.

&lt;/p&gt;&lt;p&gt;&lt;b&gt;Example using gems:&lt;/b&gt;&lt;/p&gt;&lt;pre&gt; $JRUBY_HOME/bin/gem.bat install rails -y --no-ri --no-rdoc
&lt;/pre&gt;&lt;h4&gt;&lt;a name='Why_does_my_db:migrate_fail_with_&amp;quot;undefined_method__create_database__for_class__#&amp;lt;Class:01x1e30857&amp;gt;_&amp;quot;?'&gt;&lt;/a&gt; Why does my db:migrate fail with &amp;quot;undefined method 'create_database' for class '#&amp;lt;Class:01x1e30857&amp;gt;'&amp;quot;?&lt;/h4&gt;
&lt;p&gt;In this case, try to run the migrations with:
&lt;/p&gt;&lt;pre&gt; jruby -S rake db:migrate SKIP_AR_JDBC_RAKE_REDEFINES=1
&lt;/pre&gt;&lt;p&gt;
You can also just put the following line somewhere in your Rakefile, or in a custom Rakefile in &lt;tt&gt;lib/tasks/*.rake&lt;/tt&gt;:
&lt;/p&gt;&lt;pre&gt; ENV['SKIP_AR_JDBC_RAKE_REDEFINES'] = '1'
&lt;/pre&gt;&lt;p&gt;&lt;span id=&quot;troubleshooting_JNI&quot; /&gt;&lt;/p&gt;&lt;h4&gt;&lt;a name='I_am_having_a_weird_JNI_problem._Help_me!'&gt;&lt;/a&gt; I am having a weird JNI problem. Help me!&lt;/h4&gt;
&lt;p&gt;There are two scenarios in which JNI problems occur: 
&lt;/p&gt;&lt;ul&gt;&lt;li&gt; When the jar is in JRuby 1.1.2's lib.
&lt;/li&gt;&lt;li&gt; When the jar is loaded using ruby's &amp;quot;require&amp;quot; statement in JRuby &amp;lt; 1.1.
&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;These two scenarios are described below.

&lt;/p&gt;&lt;h5&gt;&lt;a name='JRuby_1.1.2_+'&gt;&lt;/a&gt; JRuby 1.1.2 + &lt;/h5&gt;
&lt;p&gt;JRuby 1.1.2 changed how it set up the classpath. Earlier versions merged the CLASSPATH environment variable with all .jar files in &lt;tt&gt;JRUBY_HOME/lib&lt;/tt&gt; and passed them to the JVM via the &lt;tt&gt;-classpath&lt;/tt&gt; option. JRuby 1.1.2 instead passes all &lt;tt&gt;.jar&lt;/tt&gt; files in &lt;tt&gt;lib&lt;/tt&gt; to the JVM via the &lt;tt&gt;-Xbootclasspath/a:&lt;/tt&gt; option, while CLASSPATH is passed using &lt;tt&gt;-classpath&lt;/tt&gt;. Jar files that use JNI (e.g. &lt;tt&gt;sqljdbc.jar&lt;/tt&gt;) don't work correctly when they're in the boot classpath, so they should not be placed in JRuby's &lt;tt&gt;lib&lt;/tt&gt; directory. Instead, they should be loaded with &lt;tt&gt;require&lt;/tt&gt; or by setting the CLASSPATH environment variable.

&lt;/p&gt;&lt;h5&gt;&lt;a name='JRuby_&amp;lt;_1.1'&gt;&lt;/a&gt; JRuby &amp;lt; 1.1 &lt;/h5&gt;
&lt;p&gt;In older versions of JRuby (pre 1.1), loading a jar into multiple JRuby runtimes with &lt;tt&gt;require&lt;/tt&gt; can cause problems with JNI. For example, when using Microsoft SQL Server and integrated security in a rails application with &lt;tt&gt;sqljdbc&lt;/tt&gt; loaded with a &lt;tt&gt;require&lt;/tt&gt; statement, running &lt;tt&gt;jruby&lt;/tt&gt; &lt;tt&gt;-S&lt;/tt&gt; &lt;tt&gt;rake&lt;/tt&gt; &lt;tt&gt;test:units&lt;/tt&gt; results in the following error:
&lt;/p&gt;&lt;pre&gt; com.microsoft.sqlserver.jdbc.AuthenticationJNI
 &amp;lt;clinit&amp;gt;
 WARNING: Failed to load the sqljdbc_auth.dll
&lt;/pre&gt;&lt;p&gt;
The error message is displayed because &lt;tt&gt;sqljdbc.jar&lt;/tt&gt; 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. There are two ways to work around this problem.

&lt;/p&gt;&lt;ul&gt;&lt;li&gt; Load the jar on the classpath instead of using &lt;tt&gt;require&lt;/tt&gt;. This will cause it to be loaded by a different class loader, so the jar file will only be loaded once per process.
&lt;/li&gt;&lt;li&gt; Tell JRuby to launch other jrubies out-of-proc with &lt;br /&gt;&lt;tt&gt;jruby &lt;b&gt;-J-Djruby.launch.inproc=false&lt;/b&gt; &lt;i&gt;rest of command&lt;/i&gt;&lt;/tt&gt;&lt;br /&gt; This will cause a second JVM to be launched in the &lt;tt&gt;rake&lt;/tt&gt; &lt;tt&gt;test:units&lt;/tt&gt; example above.
&lt;/li&gt;&lt;/ul&gt;&lt;h4&gt;&lt;a name='I_tried_the_--server_option_and_received_an_error'&gt;&lt;/a&gt; I tried the --server option and received an error&lt;/h4&gt;
&lt;p&gt;You tried the performance tuning option --server but received an error like &amp;quot;Error: no `server' JVM at `c:\Program Files\Java\jre6\bin\server\jvm.dll'.&amp;quot;
On windows the Java Runtime Environment (JRE) does not include the server VM. You should download an install the Java Development Kit (JDK). 
If you want to use the server with the JRE, you can copy JDK's jre\bin\server folder to a bin\server directory in the Java SE Runtime Environment.&lt;/p&gt;</text-as-html>
  <updated-at type="datetime">2009-07-12T03:02:11Z</updated-at>
  <wiki-id type="integer">320</wiki-id>
</page>
