So I guess that I am making a lot of the newbie mistakes, as I have finally put JRuby and Wicket into a pom.xml file and started trying to get my favorite web framework and my favorite language to play nice. Naively, I thought that I could create a Ruby class that would be seen by Java as a Java class pretty trivially. But line 9 of https://gist.github.com/mikepence/6804479 tries to find a Java class by referencing HomePage.class. I have translated HomePage.java to HomePage.rb with my best first guess (https://gist.github.com/mikepence/6804563) but it never even gets that far. The compiler says WTF to me in the form of "java: cannot find symboll: class HomePage location: class com.mycompany.WicketApplication." So, now I know what Red Bridge is, and I recall BSF and all of that, but I just want a JRuby object that behaves like a Java object without all of that rigamarole. What am I missing?
on 2013-10-03 05:44
on 2013-10-03 06:41
Mike - I'm not confident about the answer, but it might be worth a try until someone with a clue chimes in. ;) I don't think Java code can access any Ruby classes by their class name. What if you were to inject the Ruby class object into the Application class? For example, define a setter on your application class that stores the passed class in a class variable. Then, have getHomePage return that variable. Somewhere in your app before Wicket calls getHomePage, you'd need to call setHomePage with your Ruby class. - Keith
on 2013-10-03 06:44
Mike, I don't know how you are attempting to run these or hook them together but jruby scripts require the jruby interpreter to run . So you use jruby or jruby.jar to run the scripts just like you would run ruby scripts from the command line : `jruby myscript.rb`. You can require and use java classes in your jruby scripts, like you've done, but the java side of things can't so easily see and use your ruby classes. If the java library you are using is expecting a java object, you may need to use one of the special conversion methods to make it work. If you are trying to run this as java, and expecting the wicket library to just see your ruby class as if it was a java class, that won't work. in that case, you would definitely need to use something like Red Bridge to make it work. In fact, looking into what Wicket is, and how it's run, (A Java EE web framework, etc), because the java server expects to find specific java classes in specific places in order to run things, I think you will need to write some kind of integration layer that essentially fires up your ruby scripts inside a scripting container from the java process and gets them talking. You might look into how jruby-rack and warbler accomplish this sort of thing. Sorry I can't be more help but I don't have any experience with what you are trying to do. All the best, and I hope you can figure it out. Cheers, Eric