Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you create a Java applet using JRuby?

I want to create a Java applet using JRuby. That is, I want to create a Java applet with Ruby code inside run by JRuby to do all the GUI stuff. I am looking for a simple example of how to do this to get started.

like image 220
mydoghasworms Avatar asked Mar 24 '11 18:03

mydoghasworms


People also ask

What does JRuby do?

JRuby is an open source implementation of the Ruby programming language for the Java Virtual Machine (JVM). It allows Ruby applications to be run within a Java Virtual Machine and interface with libraries written in either Java or Ruby.


1 Answers

Check out these links...

JRubyApplet from our codebase: https://github.com/jruby/jruby/blob/master/src/org/jruby/JRubyApplet.java

Rake tasks for building a signed applet: https://github.com/jruby/jruby/blob/master/rakelib/applet.rake

Source for jruby.org/tryjruby page: https://github.com/jruby/jruby.github.com/blob/master/www/tryjruby.html

For your case, you'd probably have the applet in Java, bootstrap an org.jruby.embed.ScriptingContainer instance, and then feed it the Applet instance so it can add your UI elements in a Ruby script. Anything in the applet jar can be loaded directly, e.g. require 'my_applet.rb' will look for /my_applet.rb in the jar.

Enjoy!

like image 173
Charles Oliver Nutter Avatar answered Oct 01 '22 11:10

Charles Oliver Nutter