Syntax to include custom Java classes

T

thiagobrandam

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.
 
J

James Britt

thiagobrandam said:
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 Britt

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
 
T

thiagobrandam

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

Side note: =A0There'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 ...)
=A0 =A0 =A0 =A0 - Playing with Better Toyswww.ruby-doc.org=A0 =A0 =A0 =A0 =
=A0 =A0 - Ruby Help & Documentationwww.rubystuff.com=A0 =A0 =A0 =A0 =A0 =A0=
- The Ruby Store for Ruby Stuff
 
J

James Britt

thiagobrandam said:
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 Britt

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
 
R

Robert Dober

Cool! Thanks.
I agree this was useful info, I played around with this and had some
difficulties.
No inconvenience, and I also don't know if JRuby questions are welcome h= ere
or not. The list is ruby-talk, not c-ruby-talk or mri-talk, so I vote Ye= s
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
--=20
C'est v=E9ritablement utile puisque c'est joli.

Antoine de Saint Exup=E9ry
 
T

thiagobrandam

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top