|
View:
New views
1 Messages
—
Rating Filter:
Alert me
|
|
|
Newbie questionsHi,
Here are some of my questions regarding java integration with ruby app. Thanks in advance, Kevin 1) Jruby on Rails I'm trying to have a java process created when rails app is started by 'jruby -S start/server'. I do this by putting my_init.rb under config/initializers # run on initialization include Java require "./lib/myjava.jar" java_service = ServiceInitializer.new where myjava.jar contains ServiceIntializer java class. [Q1] Is this right way to initialize java process for rails app? What is the general approach? [Problem] Even when I do other operations, for example, 'jruby -S rake db:migrate', this initialization routine seems to run. 2) Implementing java interface with jruby In my ServiceInitializer java code, I create an instance of ruby class as the implementation of one java interface. (I've used RubyFactory approach seen at http://lawrencesong.net/2008/01/implement-java-interface-in-ruby/) I wanted this ruby implementation to be able to access all rails facilities that rails app uses. [Q2] However, I had to manually connect to db and all, to get this work. Does this sound right? To me, it looks defeating its purpose of initializing from rails init. My implementation class file rubyinterfacehandler.rb had to have all these require "rubygems" require "active_record" require "app/models/dbmodel.rb" # We had to do this manually since interface is # called from outside of rails? ActiveRecord::Base::establish_connection( :adapter=>"jdbcmysql", :database=>"db_development", :pool=>5, :username=>"root", :password=>"", :host=>"localhost") class RubyInterfaceHandler def interface_method ... end end 3) Creating war with warble and putting rails on Tomcat. [Problem] My RubyFactory who is instantiating rubyinterfacehandler cannot find rubyinterfacehandler.rb file which is located in rails project directory. I see the file gets populated in WEB-INF folder when war expanded. I tried to copy the ruby files to WEB-INF/lib also inside WEB-INF/lib/myjava.jar where RubyFactory class is but all didn't work. [Q3] Where will be the root path from the java class that were in a jar file in the lib directory? How can I make it to find ruby files in rails app? [Q4] Shall I move out the java process initialization code to Tomcat web app context initialization area? Perhaps add a ContextListener? What is the general approach if I want to add webapp context init codes and still want to use warbler? 4) Running rails app using glassfish gem. [Problem] When I issue command 'glassfish', log shows followings where XXXX is the java interface class (implemented with ruby) that is in rails' lib/myjava.jar. This must be coming out from RubyFactory SEVERE: org.jruby.exceptions.RaiseException: cannot load Java class XXXX Oct 28, 2009 1:55:13 PM com.sun.grizzly.config.GrizzlyServiceListener SEVERE: java.lang.NoClassDefFoundError: XXXX from java/lang/ClassLoader.java:700:in `defineClass' from org/jruby/util/JRubyClassLoader.java:22:in `defineClass' from org/jruby/java/MiniJava.java:576:in `defineOldStyleImplClass' from org/jruby/java/MiniJava.java:194:in `createOldStyleImplClass' from org/jruby/javasupport/Java.java:1570:in `new_proxy_instance2' from org/jruby/java/proxies/JavaInterfaceTemplate.java:262:in `jcreateProxy' from org/jruby/java/proxies/JavaInterfaceTemplate.java:22:in `access$000' from org/jruby/java/proxies/JavaInterfaceTemplate.java:165:in `call' ... 132 levels... from /usr/local/jruby/lib/ruby/gems/1.8/gems/rails-2.3.4/lib/initializer.rb:113:in `run' [Q5] With glassfish, is there different way to specify classpath of rails app libs? (for GrizzlyServiceListener?) [Q6] Again, shall I move app context init code to somewhere else in case with glassfish? Is there better approach? |
| Free embeddable forum powered by Nabble | Forum Help |