<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
    <channel>
        <title>JRuby - Blogs at Near Infinity</title>


        <link>http://www.nearinfinity.com/blogs/</link>
        <description>Employee Blogs</description>
        <language>en</language>
        <copyright>Copyright 2011</copyright>
        <lastBuildDate>Fri, 01 Apr 2011 00:00:00 -0500</lastBuildDate>
        <generator>http://www.sixapart.com/movabletype/</generator>
        <docs>http://www.rssboard.org/rss-specification</docs>
        
        <item>
            <title>Introducing RJava</title>
            <description><![CDATA[<p>You've no doubt heard about JRuby, which lets you run Ruby code on the JVM. This is nice, but wouldn't it be nicer if you could write Java code on a Ruby VM? This would let you take advantage of the power of Ruby 1.9's new YARV (Yet Another Ruby VM) interpreter while letting you write code in a statically-typed language. Without further ado, I'd like to introduce <strong>RJava</strong>, which does just that!</p>

<p>RJava lets you write code in Java and run it on a Ruby VM! And you still get the full benefit of the Java compiler to ensure your code is 100% correct. Of course with Java you also get checked exceptions and proper interfaces and abstract classes to ensure compliance with your design. You no longer need to worry about whether an object responds to a random message, because the Java compiler will enforce that it does.</p>

<p>You get all this and more but on the power and flexibility of a Ruby VM. And because Java does not support closures, you are ensured that everything is properly designed since you'll be able to define interfaces and then implement anonymous inner classes just like you're used to doing! Even when JDK 8 arrives sometime in the future with lambdas, you can rest assured that they will be statically typed.</p>

<p>As a first example, let's see how you could filter a collection in RJava to find only the even numbers from one to ten. In Ruby you'd probably write something like this:</p>

<pre class="prettyprint">
evens = (1..10).find_all { |n| n % 2 == 0 }
</pre>

<p>With RJava, you'd write this:</p>

<pre class="prettyprint">
List&lt;Integer&gt; evens = new ArrayList&lt;Integer&gt;();
for (int i = 1; i &lt;= 10; i++) {
  if (i % 2 == 0) {
    evens.add(i);
  }
}
</pre>

<p>This example shows the benefits of declaring variables with specific types, how you can use interfaces (e.g. List in the example) when declaring variables, and shows how you also get the benefits of Java generics to ensure your collections are always type-safe. Without any doubt you know that "evens" is a List containing Integers and that "i" is an int, so you can sleep soundly knowing your code is correct. You can also see Java's powerful "for" loop at work here, to easily traverse from 1 to 10, inclusive. Finally, you saw how to effectively use Java's braces to organize code to clearly show blocks, and semi-colons ensure you always know where lines terminate.</p>

<p>I've just released <a href="https://github.com/sleberknight/rjava" onclick="alert('April Fools!'); return false;">RJava</a> on GitHub, so go check it out. Please download RJava today and give it a try and let me know what you think!</p>]]></description>
            <link>http://www.nearinfinity.com/blogs/scott_leberknight/introducing_rjava.html</link>
            <guid>http://www.nearinfinity.com/blogs/scott_leberknight/introducing_rjava.html</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">JRuby</category>
            
                <category domain="http://www.sixapart.com/ns/types#category">Java</category>
            
                <category domain="http://www.sixapart.com/ns/types#category">Ruby</category>
            
            
                <category domain="http://www.sixapart.com/ns/types#tag">java</category>
            
                <category domain="http://www.sixapart.com/ns/types#tag">ruby</category>
            
            <pubDate>Fri, 01 Apr 2011 00:00:00 -0500</pubDate>
        </item>
        
        <item>
            <title>Session Storage in JRuby on Rails</title>
            <description><![CDATA[There are many ways to store sessions in Ruby on Rails, but by using JRuby, we get another option that I think supersedes the common solutions... Using the Java Server's built in session store.<br /><br /><h2>First... The implementation</h2>
This is assuming that you are running JRuby and using a tool like warbler to deploy to a Java server like Tomcat.<br /><br />config/initializers/session_store.rb<br />
<pre class="prettyprint"># check if we're running in a java container
if defined?($servlet_context)
    require 'action_controller/session/java_servlet_store'
    # tell rails to use the java container's session store
    ActionController::Base.session_store = :java_servlet_store
else
    # other session store for development in webrick/mongrel<br />    # setup cookie based session<br />    ActionController::Base.session = {<br />        :key    =&gt; '_dd_session',<br />        :secret =&gt; '&lt;Your really long random secret key&gt;'<br />    }<br />end
</pre>This will store your rails session in Tomcat's session store exactly as if you were running a Java web framework.<br />
<br /><h2>Second... Why?</h2>There are a few common solutions starting with the rails default.<br /><br /><b>Cookie Store:</b> This is not very secure, limited in size, and sends a lot of data back and forth to the client. It is strongly recommended to not use this for production systems.<br /><b>File Store:</b> Stores sessions on the file system. Every cookie access involves file system IO. Does not support clustering by default but can be achieved through a SAN or shared storage.<br /><b>ActiveRecord:</b> Stores sessions in the database. Slow due to database IO. Natively supports clustering.<br /><b>Memcached:</b> Stores sessions in Memcached instance. Very popular and works well with clusters. Can run into RAM issues on systems with lots of users. Requires an instance of Memcached running.<br /><b>Java Servlet Store:</b> Works just like your other Java applications. Java Servers can be configured to cluster sessions. Uses the JSESSIONID cookie or url param (in Tomcat)<br /><br /><h2>Conclusion</h2>This won't be the solution for everyone, but if you're deploying a JRuby on Rails app into an infrastructure based on Java, then it provides a simple and efficient solution.<br />]]></description>
            <link>http://www.nearinfinity.com/blogs/andrew_avenoso/session_storage_in_jruby_on_ra.html</link>
            <guid>http://www.nearinfinity.com/blogs/andrew_avenoso/session_storage_in_jruby_on_ra.html</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">JRuby</category>
            
                <category domain="http://www.sixapart.com/ns/types#category">Java</category>
            
                <category domain="http://www.sixapart.com/ns/types#category">Ruby</category>
            
                <category domain="http://www.sixapart.com/ns/types#category">Web Development</category>
            
            
                <category domain="http://www.sixapart.com/ns/types#tag">jruby</category>
            
                <category domain="http://www.sixapart.com/ns/types#tag">ruby</category>
            
                <category domain="http://www.sixapart.com/ns/types#tag">session</category>
            
                <category domain="http://www.sixapart.com/ns/types#tag">tomcat</category>
            
            <pubDate>Mon, 09 Aug 2010 12:30:00 -0500</pubDate>
        </item>
        
        <item>
            <title>Finding Holes in Rcov and JRuby</title>
            <description><![CDATA[<h2>"We're missing some coverage..."</h2>

<p>While creating coverage reports for a fairly new JRuby on Rails project, we noticed that our coverage numbers weren't <em>quite</em> right: certain classes were missing from the coverage reports. Rcov doesn't know about classes unless they are required: not a problem for models, but we were missing tests for some controllers and libraries.</p>

<p>Oops.</p>

<p>To properly correct this problem, I wrote the <code>coverage_helper</code> (to live alongside the <code>test_helper</code>).  Basically, this causes all of the classes to be required so that rcov knows about them.</p>

<h4>test\coverage_helper.rb</h4>

<pre><code>require 'test/unit'
require 'test_helper'

class CoverageHelper &lt; Test::Unit::TestCase
  def test_coverage
    ['app', 'lib'].each {|path| Dir.glob("#{path}/**/*.rb") {|file| 
      require File.expand_path(file.chomp('.rb'))
    }}
    assert true
  end
end
</code></pre>

<p>Simply include this test in your rcov builds and the problem is solved.  </p>

<p>Because of how rcov counts lines and the way Ruby class loading works, you'll never see files with 0% coverage.  However, at least you <em>will</em> see all of your classes listed and those that aren't covered will have a low percentage.</p>

<h4>Is this really necessary?</h4>

<p>First, the <code>File.expand_path</code> makes sure that your files are only required once.  I hate random warning messages because constants are initialized twice (among other issues).</p>

<p>Second, no, I didn't need to make this a test, but it just seemed nicer to.  I added the  <code>assert true</code> simply because I didn't feel right about not asserting <em>something</em> in the test.  </p>

<p>Third, as long as one uses the Rails scripts to generate the skeletons for your code, this scenario <em>should</em> never happen (because Rails will create all of the appropriate tests).  However, there is the tendency not to use the generated scripts when they don't output what you want, which is what we have discovered (Rails and Legacy Database Schemas aren't a perfect fit).  Also, sometimes I just forget to use them.</p>

<h2>What if you can't run rcov?</h2>

<p>One minor glitch of running JRuby on Windows is that the <code>File.separator</code> is technically incorrect (it's '<code>/</code>' instead of '<code>\</code>').  This usually isn't an issue... except when using rcov.  Since rcov executes from the shell, the arguments requiring file names and/or directories won't work because the separator is the wrong direction from what Windows is expecting.</p>

<p>The fix is to add a couple of methods to the File class to address the problem.</p>

<h4>Windows Separator Fix</h4>

<pre><code>class File
  @@is_windows = ENV['OS'] &amp;&amp; 
    (not ENV['OS'].downcase.match(/^windows/).nil?)

  def self.fix_name(name)
    @@is_windows ? name.tr(File::SEPARATOR, File::ALT_SEPARATOR) : name
  end

  def self.fixed_join(*files)
    self.fix_name(self.join files)
  end
end
</code></pre>

<p>The reason to do the <code>ENV['OS']</code> truth check first is that in JRuby on Solaris (where our CI is), that property doesn't exist. We couldn't use the <code>RUBY_PLATFORM</code> variable either, as in JRuby it's always assigned to '<code>java</code>'.</p>

<p>I should note that I've only use these fixed separator methods when necessary (in my rcov rake task).  The 'normal' separator has worked in every other situation I've run into.</p>
]]></description>
            <link>http://www.nearinfinity.com/blogs/brian_montgomery/finding_holes_in_rcov_and_jrub.html</link>
            <guid>http://www.nearinfinity.com/blogs/brian_montgomery/finding_holes_in_rcov_and_jrub.html</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">JRuby</category>
            
                <category domain="http://www.sixapart.com/ns/types#category">Ruby</category>
            
                <category domain="http://www.sixapart.com/ns/types#category">Testing</category>
            
            
            <pubDate>Tue, 27 Jan 2009 17:40:42 -0500</pubDate>
        </item>
        
        <item>
            <title>Groovy Fun With ObjectRange</title>
            <description><![CDATA[<p>I ran into a situation the other day with Groovy that baffled me at first. Let's create a range  from 0.0 to 10.0 and then use it to check if a certain number is contained within that range, like this:</p>

<pre class="prettyprint">groovy:000> r = 0.0..10.0
===> 0.0..10.0
groovy:000> r.contains(5.6)
===> false
</pre>

<p>WTF? The number 5.6 is <i>not</i> contained in the range 0.0 to 10.0? I beg to differ. So what's actually going on here? Using the shell we can do some more digging, interrogating the range object to see what its bounds are, what values it contains if you iterate it, and so on:</p>

<pre class="prettyprint">groovy:000> r = 0.0..10.0
===> 0.0..10.0
groovy:000> r.class
===> class groovy.lang.ObjectRange
groovy:000> r.from.class
===> class java.math.BigDecimal
groovy:000> r.to.class
===> class java.math.BigDecimal
groovy:000> r.each { print " $it " }  
 0.0  1.0  2.0  3.0  4.0  5.0  6.0  7.0  8.0  9.0  10.0 ===> 0.0..10.0
groovy:000> r.contains 5 
===> true
groovy:000> r.contains 5.0
===> true
groovy:000> r.contains 5.6
===> false
</pre>

<p>So what did we learn? First, the range is an <code>ObjectRange</code> whose bounds are <code>BigDecimal</code>s. Second, that iterating by default iterates in increments of one. And third that the <code>contains</code> method does not quite do what I would expect by default. Looking at Groovy's <code>ObjectRange</code> class makes it clear exactly what's going on, so let's look:</p>

<pre class="prettyprint">public boolean contains(Object value) {
  Iterator it = iterator();
  if (value == null) return false;
  while (it.hasNext()) {
    try {
      if (DefaultTypeTransformation.compareEqual(value, it.next())) return true;
    } catch (ClassCastException e) {
      return false;
    }
  }
  return false;
}
</pre>

<p>The Groovy <code>ObjectRange</code>'s <code>contains</code> method defines containment as whether a value is contained within the values <i>generated by its iterator</i>. By now many of my <b>many millions</b> of readers are about to post a comment telling me the problem, so I'll preempt that temptation by adding a few more lines of interaction with the Groovy shell:</p>

<pre class="prettyprint">groovy:000> r.containsWithinBounds 5.0
===> true
groovy:000> r.containsWithinBounds 5.6
===> true
</pre>

<p>Aha! So <code>contains</code> doesn't do what you might think it should, but <code>containsWithinBounds</code> does. Its JavaDoc says "Checks whether a value is between the from and to values of a Range." Conspicuously there is no JavaDoc on the <code>contains</code> method to tell me that what it actually does is check whether a value is contained within the <i>discrete values</i> generated by the iterator. Let's try more more thing:</p>

<pre class="prettyprint">groovy:000> r.containsWithinBounds 5
ERROR java.lang.ClassCastException: java.lang.Integer
        at groovysh_evaluate.run (groovysh_evaluate:2)
        ...
</pre>

<p>Oops! Not only do you need to call <code>containsWithinBounds</code> rather than <code>contains</code>, you also need to call it with the correct type, as there is no coercion going on since it uses <code>Comparable.compareTo()</code> under the covers.</p>

<p>Notwithstanding all the recent activity regarding all the <a href="http://www.ruby-forum.com/topic/157034">Ruby security flaws</a> recently discovered, how does Ruby handle inclusion of a number within a range? Here's some irb output:</p>

<pre class="prettyprint">>> r = 0.0..10.0
=> 0.0..10.0
>> r.class
=> Range
>> r.begin.class
=> Float
>> r.end.class
=> Float
>> r.each { |item| print " #{item} " }
TypeError: can't iterate from Float
        from (irb):53:in `each'
        from (irb):53
>> r.include? 5
=> true
>> r.include? 5.0
=> true
>> r.include? 5.6
=> true
</pre>

<p>To me this is more <i>semantically</i> and <i>intuitively</i> correct behavior. First, while I can create a range with float bounds, I cannot iterate that range - for <i>non-integral</i> numbers, how exactly can you define the next item after 0.0 for example? 0.1, 0.01, 0.001, and so on till infinity. Second, the <code>include?</code> method behaves as I would expect no matter what type of argument I pass. I am able to iterate ranges of integral numbers, however, which could arguably also be confusing since the behavior of the method depends on the type. Then again, that's pretty much what polymorphic method behavior is about I suppose.</p>

<pre class="prettyprint">>> r = 0..10
=> 0..10
>> r.each { |item| print " #{item} " }
 0  1  2  3  4  5  6  7  8  9  10 => 0..10
</pre>

<p>In the case of integers Ruby uses an increment of one by default. You could use the <code>step</code> method to get a different increment, e.g.:</p>

<pre class="prettyprint">>> r.step(2) { |item| print " #{item} " }
 0  2  4  6  8  10 => 0..10
</pre>

<p>So what's the point of all this? That Ruby is better than Groovy? Nope. I really like both languages. I think there are a couple of points that were reinforced to me:</p>

<p>First, RTFM (or source code --> RTFC). Even though Groovy's <code>contains</code> method doesn't behave how <i>I</i> think it should, there is the method I was looking for with <code>containsWithinBounds</code>.</p>

<p>Second, having a shell to play around with short snippets of code is really, really useful, without needing to create a class with a main method just to play around with code.</p>

<p>Third, documentation and semantics matter. If something doesn't feel intuitively correct based on how similar things act, it is more likely to cause confusion and errors. In this case, since my unit test immediately caught the error, I was able to figure the problem out in a few minutes.</p>

<p>Finally, following on from the last point, unit tests continue to remain valuable. Of course anyone who knows me would roll their eyes over my anal-ness (which Mac's dictionary is telling me is not really a word but I don't care at the moment) expecting me to get something about unit testing in somehow.</p>]]></description>
            <link>http://www.nearinfinity.com/blogs/scott_leberknight/groovy_fun_with_objectrange.html</link>
            <guid>http://www.nearinfinity.com/blogs/scott_leberknight/groovy_fun_with_objectrange.html</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">Groovy</category>
            
                <category domain="http://www.sixapart.com/ns/types#category">JRuby</category>
            
            
                <category domain="http://www.sixapart.com/ns/types#tag">groovy</category>
            
                <category domain="http://www.sixapart.com/ns/types#tag">range</category>
            
                <category domain="http://www.sixapart.com/ns/types#tag">ruby</category>
            
            <pubDate>Wed, 25 Jun 2008 15:34:02 -0500</pubDate>
        </item>
        
        <item>
            <title>JRuby script in a signed jar</title>
            <description><![CDATA[OK, let's dive into the world of JRuby a little further, specifically let's touch on the boundary between Java and JRuby again.  One excellent way to run JRuby for certain situations is to put the JRuby code (along with some Java code) in a signed, executable jar.  A fairly common reason to do this would be the following: you want to run some ruby code (in the JVM) and you want to make sure that no one modifies the contents of the JRuby file (thus you sign the jar).  Of course this does not offer you perfect protection, but it adds another layer making it more difficult to subvert your efforts.  For the time being, I will assume that you have JDK 1.5 and not JDK 1.6... which means that the scripting framework is not available to you.  So, simply include the JRuby jar file in your classpath and jar up the following class along with your ruby files.  You should be sure to sign the jar when you create it and you should add pkg.JRubyRunner as your main class so the jar file is executable.  Then executing "java -cp jruby.jar -jar MyJar.jar" will run your jruby code AND since the jar file is signed no one will be able to modify your ruby files!  (Again, with some effort of course a hacker could modify the ruby file if they had access to the jar.) 

<pre class="prettyprint">package pkg;

import org.jruby.Main;

public class JRubyRunner {
  public static void main(String[] args) throws Exception {
    runJRubyScript("ipc.rb", args);
  }

  public static void runJRubyScript(String name, String... args) {
    // modify the args for jruby
    String[] args2 = new String[2 + args.length];
    if (args.length &gt; 0) {
      System.arraycopy(args, 0, args2, 2, args.length);
    }
    args2[0] = "-e";
    args2[1] = "require '" + name + "'";
    // execute the ruby script
    Main.main(args2);
  }
}

</pre>


Now, for a few subtle points that you may have missed, especially considering the simplicity of the code.  For starters, why you may ask, not just pass in the name of the ruby file?  Why use the -e option at all?  Well, the reason is because the ruby file is located in the jar file so it is not accessible via java.io.File which JRuby uses to load the file.  This makes perfect sense.  And since it defeats the purpose to move the ruby file outside of the signed jar, we must find another way to get this to work.  You could read in the entire contents of the file from the classpath and pass it into the -e option, but this is ugly and extremely prone to error, so we take advantage of an excellent feature of 'require' in JRuby.  Require loads its files from the classpath.  This is excellent, because it means that if we require just the file we want to run, it will be loaded from the classpath and and subsequent requires will be loaded from the classpath as well.]]></description>
            <link>http://www.nearinfinity.com/blogs/bryan_weber/jruby_script_in_a_signed.html</link>
            <guid>http://www.nearinfinity.com/blogs/bryan_weber/jruby_script_in_a_signed.html</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">JRuby</category>
            
            
            <pubDate>Mon, 30 Jul 2007 21:28:15 -0500</pubDate>
        </item>
        
        <item>
            <title>Configuring JRuby in IntelliJ IDEA 6.0.5</title>
            <description><![CDATA[So you know Java, you've played around with Ruby and now you are interested in trying out JRuby in your favorite IDE (which naturally is IntelliJ IDEA) or maybe you just want to try out Ruby/JRuby... Unfortunately, JetBrains is still a little behind with their Ruby, and especially JRuby, support for IntelliJ. But have no fear, just follow the steps below and you'll be up and running without too much trouble.<p>
<small>[Legal disclaimer: This was tested on Mac OS X with Java 1.5, JRuby 1.0 and IntelliJ 6.0.5, but should work on any Windows or *nix based system with IntelliJ 6.0.x and the JRuby 0.1 plugin.]</small></p><p>
<small>[Legal disclaimer: The screen shots in these instructions are not actually perfect or exactly what you will see at all stages of the process, however they should contain all the information required.]</small>

</p><ol>
<li>
Install Ruby Plugin for IntelliJ <a href="http://www.jetbrains.net/confluence/display/RUBYDEV/Ruby+Plugin+0.1+Release+Notes">Instructions (Leaves this page)</a> [Don't look for a JRuby plugin, install the Ruby plugin.]
</li>
<li>
Download and Install JRuby (unzip to the desired installation directory) <a href="http://jruby.codehaus.org/Getting+Started">Instructions (Leaves this page)</a>
</li>
<li>
[UPDATE: I PUT IN A FEATURE REQUEST AND JETBRAINS INCLUDED IT SO NOW THERE IS SUCH A THING AS A JRUBY SDK SO THIS STEP IS NO LONGER REQUIRED!  YEAH JETBRAINS!!!!]
Create a Ruby link (*nix) or bat file (Windows) [UPDATE: Creating a bat file named ruby.bat does NOT work.  IntelliJ looks for ruby.exe which makes this trick more of a pain... On Windows it is probably simpler to create an External Tool for JRuby right now.  That way you can right click on a file and execute it and it doesn't require any fancy hacks.  Instructions for creating/configuring the "external tool" are below.] that points to the JRuby executable [The IntelliJ plugin requires the executable file be called "ruby" and not "jruby" so we simply trick it by creating a file that points to the real JRuby executable.  Hopefully JetBrains will change this for future releases.]
<ul>
<li>*nix soft link:
ln -s jruby ruby
</li>
</ul>
</li>
<li>
Create a project with a Ruby module (note: create a Ruby module <b>NOT</b> a JRuby module as you won't find any such thing as a JRuby module. Nor do you need one for that matter, as the Ruby module will do just fine thank you very much.  I suppose that JRuby wouldn't be very good if it couldn't just replace Ruby as that is what it is designed to do after all!  Well, sort of anyway.)<p>
</p><span class="mt-enclosure mt-enclosure-image" style="display: inline;"><a href="http://www.nearinfinity.com/blogs/assets/bweber/jruby%20intellij%206_0_5%20image%201.png"><img alt="jruby intellij 6_0_5 image 1.png" src="http://www.nearinfinity.com/blogs/assets_c/2008/12/jruby%20intellij%206_0_5%20image%201-thumb-600x220.png" class="mt-image-none" style="" height="220" width="600" /></a></span><br />

</li><li>
Point IntelliJ to your JRuby SDK<p>
</p><span class="mt-enclosure mt-enclosure-image" style="display: inline;"><a href="http://www.nearinfinity.com/blogs/assets/bweber/jruby%20intellij%206_0_5%20image%202.png"><img alt="jruby intellij 6_0_5 image 2.png" src="http://www.nearinfinity.com/blogs/assets_c/2008/12/jruby%20intellij%206_0_5%20image%202-thumb-600x375.png" class="mt-image-none" style="" height="375" width="600" /></a></span><br />
<span class="mt-enclosure mt-enclosure-image" style="display: inline;"><a href="http://www.nearinfinity.com/blogs/assets/bweber/jruby%20intellij%206_0_5%20image%203.png"><img alt="jruby intellij 6_0_5 image 3.png" src="http://www.nearinfinity.com/blogs/assets_c/2008/12/jruby%20intellij%206_0_5%20image%203-thumb-600x496.png" class="mt-image-none" style="" height="496" width="600" /></a></span><br />

</li></ol>
<p>

</p><p>
So now you can execute Ruby files using JRuby as your runtime in IntelliJ. But what if you want to call out to some Java code?  In JRuby you have to manage the classpath if you want to call out to java classes.  You can do this by setting the $CLASSPATH environment variable or by using the $CLASSPATH global variable. (which is only accessible after you have executed the " require 'java' " statement) Unfortunately, IntelliJ does not set either value when including a Java module.  To be fair, the latter case wouldn't really be possible because of the sequencing that is required, but hopefully they do add support so that in the future the $CLASSPATH environment variable is set automatically for you so classpath dependencies can be managed by the IDE just like for other projects/modules.
</p><p>

The EASY CASE (Ruby modules only)<br />
</p><ol>
<li>
Create java_cp file and enter classpath values [NOTE: Classpath values must end with a trailing slash due to the implementation of the java module in JRuby.]<p>
</p><span class="mt-enclosure mt-enclosure-image" style="display: inline;"><a href="http://www.nearinfinity.com/blogs/assets/bweber/jruby%20intellij%206_0_5%20image%204.png"><img alt="jruby intellij 6_0_5 image 4.png" src="" class="mt-image-none" style="" height="" width="600" /></a></span><p>

</p></li><li>
Include java_cp after java and before including any classes<p>
</p><span class="mt-enclosure mt-enclosure-image" style="display: inline;"><a href="http://www.nearinfinity.com/blogs/assets/bweber/jruby%20intellij%206_0_5%20image%205.png"><img alt="jruby intellij 6_0_5 image 5.png" src="http://www.nearinfinity.com/blogs/assets_c/2008/12/jruby%20intellij%206_0_5%20image%205-thumb-600x334.png" class="mt-image-none" style="" height="334" width="600" /></a></span><p>

</p></li><li>
Run files by right clicking on the file and choosing Run or by selecting the file and hitting the Run shortcut key sequence.
</li>
</ol>
<p>

The HARDER CASE (Ruby modules and Java modules in the same project)<br />
</p><ol>
<li>
Change the ruby project SDK to Java (Otherwise your Ruby module will be fine but your Java modules will not work due to a bug in the Plugin.)
<span class="mt-enclosure mt-enclosure-image" style="display: inline;"><a href="http://www.nearinfinity.com/blogs/assets/bweber/jruby%20intellij%206_0_5%20image%206.png"><img alt="jruby intellij 6_0_5 image 6.png" src="http://www.nearinfinity.com/blogs/assets_c/2008/12/jruby%20intellij%206_0_5%20image%206-thumb-600x375.png" class="mt-image-none" style="" height="375" width="600" /></a></span>
<p>See, I told you, you get an irrelevant, nasty error message!

</p></li><li>
Create a JRuby External Tool (Carefully note the parameters and working directory used. Notice that I made the working directory the lib directory where I put my source file(s).  This screen shot is inconsistent with the other screen shots taken because it came from another project, so just take my word for it. :))<p>
</p><span class="mt-enclosure mt-enclosure-image" style="display: inline;"><a href="http://www.nearinfinity.com/blogs/assets/bweber/jruby%20intellij%206_0_5%20image%207.png"><img alt="jruby intellij 6_0_5 image 7.png" src="http://www.nearinfinity.com/blogs/assets_c/2008/12/jruby%20intellij%206_0_5%20image%207-thumb-600x375.png" class="mt-image-none" style="" height="375" width="600" /></a></span><p>

</p></li><li>
Run your Ruby files by selecting the file and choosing Tools -&gt; JRuby.  
</li>
</ol>
<p>
So, there currently is not a perfect solution for running JRuby in IntelliJ IDEA, however these few steps should get you up and running in a minimal amount of time.  In the simple case there are only really two steps that are required that wouldn't be present if you were just using the Ruby plugin itself: creating the link to the executable file and managing the classpath manually (in this case via an included file jruby_cp).</p>]]></description>
            <link>http://www.nearinfinity.com/blogs/bryan_weber/configuring_jruby_in_intellij_idea.html</link>
            <guid>http://www.nearinfinity.com/blogs/bryan_weber/configuring_jruby_in_intellij_idea.html</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">JRuby</category>
            
            
            <pubDate>Wed, 04 Jul 2007 22:20:46 -0500</pubDate>
        </item>
        
        <item>
            <title>NFJS in general and JRuby in specific</title>
            <description><![CDATA[Several of the NearInfinity developers went to the Reston stop of the <a href="http://www.nofluffjuststuff.com/">No Fluff Just Stuff</a> conference. Some of the conferences were especially interesting. It was thrilling to hear strong, detailed skepticism of SOA from the expert panel. The arms race with .Net to host other programming languages has gone wild!
<ul>
<li><a href="http://sourceforge.net/projects/jhaskell">JHaskell</a>.
</li><li><a href="http://sleep.hick.org/">Sleep</a>. Quoted from the site: <i>Sleep is heavily inspired by Perl with bits of Objective-C thrown in</i>
</li><li><a href="http://java-source.net/open-source/scripting-languages/dynamicjava">Dynamic Java</a>. 
</li><li><a href="http://groovy.codehaus.org/">Groovy</a> seems like Java "lite." The groovy compiler reportedly accepts most Java source, but also permits a more flexible yet terse syntax. This gained a lot of traction at the conference. Some people complained that the name sounded too much like "Ruby." Which leads to...
</li><li><a href="http://jruby.codehaus.org/">JRuby</a>. The overall goal is to mate the slick Ruby syntax with the mature Java VM. I'm very hesitant to seriously consider it for a few reasons:
<ol>
<li>The interpreter will variously introduce bugs and <a href="http://jruby.codehaus.org/Limitations">lack features</a>. This will be an ongoing issue as Ruby is an advanced, relatively young language; 2.0 is under active development.
</li><li>The Ruby VM will get much better over time. When it does, the argument for using the excellent Java VM will be much weaker.
</li></ol>
</li><li>For better or worse, I didn't see a competitor to <a href="http://www.codeproject.com/dotnet/intro_fortran.asp">Fortran.NET</a>
</li></ul>]]></description>
            <link>http://www.nearinfinity.com/blogs/seth_schroeder/nfjs_in_general_and_jruby.html</link>
            <guid>http://www.nearinfinity.com/blogs/seth_schroeder/nfjs_in_general_and_jruby.html</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">JRuby</category>
            
                <category domain="http://www.sixapart.com/ns/types#category">Java</category>
            
            
            <pubDate>Mon, 30 Apr 2007 18:43:14 -0500</pubDate>
        </item>
        
    </channel>
</rss>

