Using Rubygems to Package Java Jarfiles

Discussion in 'Ruby' started by Rich Apodaca, Sep 12, 2006.

  1. Rich Apodaca

    Rich Apodaca Guest

    Ruby Java Bridge (RJB) (http://rjb.rubyforge.org/) a good way to use
    Java classes and maintain the abiltity to work with both C extensions
    and develop Rails applications.

    If you could package Java jarfiles in a Rubygem, that would be the
    ultimate in convenience. A user could simply use the "gem install"
    command, which would automatically install RJB if needed, the jarfile,
    and any necessary Ruby glue code. The user could then have access to the
    Java library.

    The whole process would be essentially the same as working with any
    other Rubygem. Any library that depends on this java-ruby hybrid can use
    it like any other Rubygem, with all of the advantages.

    I've already built a Gem that installs a jarfile. Here's the problem:
    with RJB, the jarfiles you use can be specified with:

    ENV['CLASSPATH'] = 'my_jarfile.jar'

    My question is: how do I locate my_jarfile.jar?

    One possibility seems to be Gem.dir, which gives the top-level directory
    for installed Gems.

    But I need to get the path to my Gem's directory. One way I came up with
    was to use (assuming I've got foo-0.1.0):

    gem_path = Gem.dir + '/gems/foo-0.1.0/'
    ENV['CLASSPATH'] = gem_path + 'my_jarfile.jar'

    I've used this approach and it works. But it seems like there must be a
    more elegant way to get to a particluar Gem's installation directory.
    Also, is there a better way to do what I'm trying to do?

    thanks,
    Rich

    --
    Posted via http://www.ruby-forum.com/.
     
    Rich Apodaca, Sep 12, 2006
    #1
    1. Advertising

  2. Rich Apodaca

    Ola Bini Guest

    Rich Apodaca wrote:
    > Ruby Java Bridge (RJB) (http://rjb.rubyforge.org/) a good way to use
    > Java classes and maintain the abiltity to work with both C extensions
    > and develop Rails applications.
    >
    > If you could package Java jarfiles in a Rubygem, that would be the
    > ultimate in convenience. A user could simply use the "gem install"
    > command, which would automatically install RJB if needed, the jarfile,
    > and any necessary Ruby glue code. The user could then have access to the
    > Java library.
    >
    > The whole process would be essentially the same as working with any
    > other Rubygem. Any library that depends on this java-ruby hybrid can use
    > it like any other Rubygem, with all of the advantages.
    >
    > I've already built a Gem that installs a jarfile. Here's the problem:
    > with RJB, the jarfiles you use can be specified with:
    >
    > ENV['CLASSPATH'] = 'my_jarfile.jar'
    >
    > My question is: how do I locate my_jarfile.jar?
    >
    > One possibility seems to be Gem.dir, which gives the top-level directory
    > for installed Gems.
    >
    > But I need to get the path to my Gem's directory. One way I came up with
    > was to use (assuming I've got foo-0.1.0):
    >
    > gem_path = Gem.dir + '/gems/foo-0.1.0/'
    > ENV['CLASSPATH'] = gem_path + 'my_jarfile.jar'
    >
    > I've used this approach and it works. But it seems like there must be a
    > more elegant way to get to a particluar Gem's installation directory.
    > Also, is there a better way to do what I'm trying to do?
    >
    > thanks,
    > Rich
    >


    Hi Rich,

    We're working on an approach like this for packaging Java extensions to
    Ruby systems. If we get what we want, you'll be able to (from JRuby) do
    gem install mongrel, choose java-version (instead of linux or mswin32)
    from the list, and the Java extension will be automatically installed.
    This requires the JRuby runtime to work, of course.

    --
    Ola Bini (http://ola-bini.blogspot.com)
    JvYAML, RbYAML, JRuby and Jatha contributor
    System Developer, Karolinska Institutet (http://www.ki.se)
    OLogix Consulting (http://www.ologix.com)

    "Yields falsehood when quined" yields falsehood when quined.
     
    Ola Bini, Sep 12, 2006
    #2
    1. Advertising

  3. Rich Apodaca

    Rich Apodaca Guest

    Ola Bini wrote:
    > Rich Apodaca wrote:
    >> The whole process would be essentially the same as working with any
    >> One possibility seems to be Gem.dir, which gives the top-level directory
    >> Also, is there a better way to do what I'm trying to do?
    >>
    >> thanks,
    >> Rich
    >>

    >
    > Hi Rich,
    >
    > We're working on an approach like this for packaging Java extensions to
    > Ruby systems. If we get what we want, you'll be able to (from JRuby) do
    > gem install mongrel, choose java-version (instead of linux or mswin32)
    > from the list, and the Java extension will be automatically installed.
    > This requires the JRuby runtime to work, of course.


    Thanks for the info, Ola. I've written an article describing another
    solution that works with the C Ruby implementation (letting you use C
    extensions _and_ Java at the same time):

    http://depth-first.com/articles/2006/09/14/cdk-the-ruby-way

    It might also work with JRuby.

    Best,
    Rich

    --
    Posted via http://www.ruby-forum.com/.
     
    Rich Apodaca, Sep 20, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jimgardener

    jstl,standard jarfiles

    jimgardener, Dec 21, 2010, in forum: Java
    Replies:
    2
    Views:
    934
    Arne Vajhøj
    Dec 21, 2010
  2. Trevor
    Replies:
    5
    Views:
    594
    Bill Kelly
    Jan 29, 2005
  3. Erik Veenstra
    Replies:
    4
    Views:
    874
    Austin Ziegler
    Feb 4, 2005
  4. kwatch
    Replies:
    0
    Views:
    114
    kwatch
    Feb 20, 2005
  5. Eric Roscher
    Replies:
    3
    Views:
    386
    Eric Roscher
    Nov 24, 2009
Loading...

Share This Page