Syntax to include custom Java classes


#1

Hi guys. This is a newbie’s question: how do I do to include custom
Java classes in a .rb file? Do I have to make a .jar file and then
call a require? If so, what’s the next thing I have to do to use a
Java class in the same .rb file? Thanks in advance.


#2

I figured out how to do.


#3

thiagobrandam wrote:

I figured out how to do.

Side note: There’s a good change that if one person has a question
about something, then someone else will, too.

If you found an answer for your problem it would be helpful to post it
here so that others can find it or reference it.

(There’s another matter of whether the original question would have been
better asked on the JRuby list, but here it is, so …)


James B.

www.happycamperstudios.com - Wicked Cool Coding
www.jamesbritt.com - Playing with Better Toys
www.ruby-doc.org - Ruby Help & Documentation
www.rubystuff.com - The Ruby Store for Ruby Stuff


#4

I don’t know if this is the best way but here it goes:

Every .class file that has a correspondent class I may use in a .rb
file, I can merge them in a .jar file. Then, I just have to call
require ‘name_of_the_file.jar’ (if it’s in the same directory). To use
a particular class, say ClassName, just call import ‘ClassName’.
Everything else is pretty much the same as though you were only using
Ruby (except for the fact that you must use jruby to interpret).

As for whether it would be better in a jruby list, I didn’t know that
the scope of this one was MRI solely. Next time I’ll think twice
before posting newbie questions in the wrong places. Sorry for any
incovenience.

Thiago


#5

thiagobrandam wrote:

I don’t know if this is the best way but here it goes:

Every .class file that has a correspondent class I may use in a .rb
file, I can merge them in a .jar file. Then, I just have to call
require ‘name_of_the_file.jar’ (if it’s in the same directory). To use
a particular class, say ClassName, just call import ‘ClassName’.
Everything else is pretty much the same as though you were only using
Ruby (except for the fact that you must use jruby to interpret).

Cool! Thanks.

As for whether it would be better in a jruby list, I didn’t know that
the scope of this one was MRI solely. Next time I’ll think twice
before posting newbie questions in the wrong places. Sorry for any
incovenience.

No inconvenience, and I also don’t know if JRuby questions are welcome
here or not. The list is ruby-talk, not c-ruby-talk or mri-talk, so I
vote Yes on general JRuby usage questions.

(Of course, I do a lot of work with JRuby, so I’m biased. But Ruby is
Ruby, and this list seems amenable to question on using C extensions and
such, so I think we’re all good.)


James B.

www.happycamperstudios.com - Wicked Cool Coding
www.jamesbritt.com - Playing with Better Toys
www.ruby-doc.org - Ruby Help & Documentation
www.rubystuff.com - The Ruby Store for Ruby Stuff


#6

On Sun, Oct 5, 2008 at 5:48 AM, James B. removed_email_address@domain.invalid
wrote:

Cool! Thanks.
I agree this was useful info, I played around with this and had some
difficulties.

As for whether it would be better in a jruby list, I didn’t know that
the scope of this one was MRI solely. Next time I’ll think twice
before posting newbie questions in the wrong places. Sorry for any
incovenience.

No inconvenience, and I also don’t know if JRuby questions are welcome here
or not. The list is ruby-talk, not c-ruby-talk or mri-talk, so I vote Yes
on general JRuby usage questions.
Well the JRuby list might have be the place to look for an answer but
I agree that this list is general enough to share it or
even ask for it, so yes I share James’ POV here.

Thanks again and just another point. Unless you have a very good
reason to top post please try bottom or inline posting the next time.
This is a long established practice on this list. No big deal however.

Cheers
Robert

C’est véritablement utile puisque c’est joli.

Antoine de Saint Exupéry


#7

Thanks again and just another point. Unless you have a very good
reason to top post please try bottom or inline posting the next time.
This is a long established practice on this list. No big deal however.

Sorry guys, I’m not used to it. I’ll obey the rules of the list.
Thanks for the help.