JRuby embedded in an Eclipse plugin (with gems in a jar)

Environment: Jruby 1.4, Eclipse 3.5

Hi,

I tried to use two new great features of JRuby 1.4.0 (JSR223
integration and Gems in a jar) inside an Eclipse plugin but ran into
some problems.
Here’s the list and the workarounds (or patches) I applied.
I put the jruby-complete.jar inside a plugin and want to run some
scripts from an other plugin.

  • Fixing the jruby.home : JRuby can’t find the right URL alone because
    Eclipse is using bundleresource URLs. So I set up the jruby.home in an
    Activator like this :

final URL jrubyHomeURL = getClass().getResource("/META-INF/jruby.home");
final BundleURLConnection con = (BundleURLConnection)
jrubyHomeURL.openConnection();
String jrubyHome = con.getLocalURL().getFile().toString();
jrubyHome = jrubyHome.replaceFirst("/$", “”);
System.setProperty(“jruby.home”,jrubyHome);

This didn’t work right away because SystemPropertyCatcher (in jruby
embed) looks for JRUBY_HOME in the environment variables first. I have
no way to override this inside my plugin so I decided to patch
SystemPropertyCatcher to not rely on the JRUBY_HOME variable. I think
that JRuby is doing the same thing internally (in RubyInstanceConfig).

  • Fixing rubygems : Rubygems has now the ability to load gems from a
    jar, but it doesn’t know how to handle bundle resources. I had to
    patch rubygems/defaults/jruby.rb to make it aware of this (in
    spec_directories_from_classpath) :

elsif u.getProtocol == ‘bundleresource’
bundle_url_connection = u.open_connection
file_url =
URI.unescape(bundle_url_connection.getLocalURL.getFile.to_s)

Is there some cleaner way to achieve that ? (I don’t like the way I
have to patch rubygems for example).

Thanks,
Gabriel.


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Hi,Gabriel.

I develop an Eclipse RCP App using JRuby.
( It names JAM Circle http://kompiro.org/jamcircle/ )
My App’s Environment is JRuby 1.3 and Eclipse 3.5.2.
But this is not a dime’s worth of difference.

  1. It is nice converter FileLocator.
    At first, if you’d like to get URL from Plug-in local Resource,
    then you should use FileLocator.It converts from “bundleresource” to
    your local protocol.
    I’ll show you an example below.

final URL jrubyHomeBundleURL =
getClass().getResource("/META-INF/jruby.home");
final File jrubyHomeFile =
org.eclipse.runtime.core.FileLocator.getBundleFile(jrubyHomeBundleURL);
System.setProperty(“jruby.home”,jrubyHome.getAbsolutePath());

  1. I don’t recommend to use JSR233 when app runs on OSGi environment.
    Because when app runs on OSGi environment, the class loader is very
    different from standard java.And if you’d like to use JRuby runtime,
    you can’t get the runtime when you use JSR233.And I’d like to use
    Readline class from Java, I gave up to use JSR233.

Regards,
Hiroki K. (a.k.a @kompiro)

2010/3/5 Gabriel G. [email protected]:




To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email


Hiroki K.
[email protected]


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Hi Gabriel,

Thanks for making great effort to get JRuby work with OSGi. I know
current JRuby has a problem to work on OSGi frameworks because JRuby
couldn’t handle OSGi specific URL. This appears while setting JRuby
home and loading libraries. However, I don’t have enough knowledge
about debugging on OSGi right now, so the problem is not yet solved.

On Fri, Mar 5, 2010 at 3:45 AM, Gabriel G. [email protected]
wrote:

  • Fixing the jruby.home : JRuby can’t find the right URL alone because
    Eclipse is using bundleresource URLs. So I set up the jruby.home in an
    Activator like this :

final URL jrubyHomeURL = getClass().getResource("/META-INF/jruby.home");
final BundleURLConnection con = (BundleURLConnection)
jrubyHomeURL.openConnection();
String jrubyHome = con.getLocalURL().getFile().toString();
jrubyHome = jrubyHome.replaceFirst("/$", “”);
System.setProperty(“jruby.home”,jrubyHome);

Maybe you got an URL something like, bundleresource://[bundle
id]/META-INF/jruby.home?


This didn’t work right away because SystemPropertyCatcher (in jruby
embed) looks for JRUBY_HOME in the environment variables first. I have
no way to override this inside my plugin so I decided to patch
SystemPropertyCatcher to not rely on the JRUBY_HOME variable. I think
that JRuby is doing the same thing internally (in RubyInstanceConfig).

Quick workaround is to unset JRUBY_HOME. JRuby doesn’t need this
environment variable to work. If you don’t have any reason to use JSR
223, would you try your code using embed core API of 1.5.0.dev. Embed
core has setHomeDirectory() method to set. Core API is more
controllable than JSR223.

  • Fixing rubygems : Rubygems has now the ability to load gems from a
    jar, but it doesn’t know how to handle bundle resources. I had to
    patch rubygems/defaults/jruby.rb to make it aware of this (in
    spec_directories_from_classpath) :

elsif u.getProtocol == ‘bundleresource’
bundle_url_connection = u.open_connection
file_url = URI.unescape(bundle_url_connection.getLocalURL.getFile.to_s)

This is because JRuby’s load service doesn’t handle bundleresouce URL.

If you have code to reproduce the problem, would you open jira and
attache it? That will help us much.

-Yoko

http://xircles.codehaus.org/manage_email


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Thanks for your answer.

  1. It is nice converter FileLocator.
    At first, if you’d like to get URL from Plug-in local Resource,
    then you should use FileLocator.It converts from “bundleresource” to
    your local protocol.

I’ll give this a try.

  1. I don’t recommend to use JSR233 when app runs on OSGi environment.
    Because when app runs on OSGi environment, the class loader is very
    different from standard java.And if you’d like to use JRuby runtime,
    you can’t get the runtime when you use JSR233.And I’d like to use
    Readline class from Java, I gave up to use JSR233.

I know that classloader is different in an OSGI environment, that’s
why I’m keeping all the JRuby dependent jars inside the same plugin.
What are you using instead of JSR223 ?

Regards,
Gabriel.


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Hi,

2010/3/5 Yoko H. [email protected]:

Hi Gabriel,

Thanks for making great effort to get JRuby work with OSGi. I know
current JRuby has a problem to work on OSGi frameworks because JRuby
couldn’t handle OSGi specific URL. This appears while setting JRuby
home and loading libraries. However, I don’t have enough knowledge
about debugging on OSGi right now, so the problem is not yet solved.

  • Fixing the jruby.home : JRuby can’t find the right URL alone because
    Eclipse is using bundleresource URLs. So I set up the jruby.home in an
    Activator like this :

Maybe you got an URL something like, bundleresource://[bundle
id]/META-INF/jruby.home?

You’re right, that’s exactly what I got.

controllable than JSR223.
I can’t rely on the fact that JRUBY_HOME is unset when the plugin is
deployed on a client computer.
But since I’m only writting JRuby script I think I’ll use the embed core
API.

If you have code to reproduce the problem, would you open jira and
attache it? That will help us much.

No much code than that : require ‘rubygems’ is ok, but require ‘dbi’
will fail. I spent more time to build the bundle.
I’ll take a look at the JRuby load service.

Regards,
Gabriel.


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs