Ruby and java?

I have a .jar file and want to use some methods form this jar file in
ruby without using jruby.
can someone help me?
thank you!

On Wed, Oct 20, 2010 at 1:32 AM, Ruben H.
[email protected]wrote:

I have a .jar file and want to use some methods form this jar file in
ruby without using jruby.
can someone help me?
thank you!


Posted via http://www.ruby-forum.com/.

Why don’t you want to use JRuby? It’s really straightforward, you can
basically interact with the Java as if it were Ruby (except sometimes
you
have to help it figure out the typing).

Josh C. wrote in post #955656:

On Wed, Oct 20, 2010 at 1:32 AM, Ruben H.
[email protected]wrote:

I have a .jar file and want to use some methods form this jar file in
ruby without using jruby.
can someone help me?
thank you!


Posted via http://www.ruby-forum.com/.

Why don’t you want to use JRuby? It’s really straightforward, you can
basically interact with the Java as if it were Ruby (except sometimes
you
have to help it figure out the typing).

I don’t want to use Jruby because my ruby code will be use by a tool
that is based on ruby not jruby (sorry for my english).

Hi,

I believe RJB (Ruby Java Bridge) is for you.
http://rubyforge.org/projects/rjb/
Rjb is Ruby extension library for 1.8.x or 1.9.1 or later and Rubinius.
And it was tested on OS X, some Linux, Windows with JSE 1.6.
But it has restriction for multithreading and may not run with Swing,
AWT etc. So if you need GUI, jruby is your choice.

You can find some document on
http://www.artonx.org/collabo/backyard/?RubyJavaBridge

  • easy start:
    set JAVA_HOME environment variable to your JDK installed directory.
    gem install rjb

script sample)

require ‘rjb’
require ‘rjbextension’ # for direct jar load

require ‘full-path-name-of-jarfile.jar’

Rjb::load # load JVM in Ruby’s
FooBar = Rjb::import(‘Foo.Bar.YourClass’) # load Class into FooBar
foobar = FooBar.new # instantiate from the
class
foobar.call_instance_method(and arguments) # invoke it.


arton [email protected]

On 20 out, 04:32, Ruben H. [email protected] wrote:

I have a .jar file and want to use some methods form this jar file in
ruby without using jruby.
can someone help me?

Mu.

Ruben H. wrote in post #955658:

Josh C. wrote in post #955656:

On Wed, Oct 20, 2010 at 1:32 AM, Ruben H.
[email protected]wrote:

I have a .jar file and want to use some methods form this jar file in
ruby without using jruby.
can someone help me?
thank you!


Posted via http://www.ruby-forum.com/.

Why don’t you want to use JRuby? It’s really straightforward, you can
basically interact with the Java as if it were Ruby (except sometimes
you
have to help it figure out the typing).

I don’t want to use Jruby because my ruby code will be use by a tool
that is based on ruby not jruby (sorry for my english).

Then you’ll have to start up an external jvm process (e.g. using
IO.popen), and talk to some Java code over stdin/stdout or over a
socket. You can’t just “use some methods” directly.

It may make more sense to run a separate jruby instance, because then
you could talk from ruby to jruby using DRb. This should be easy, given
that the target machine clearly already has a JVM.

You may be able to migrate your existing ruby code to jruby; the main
reason I can see for not doing this is if your ruby code uses C
extensions.