Help using JAR classes from NetBeans/JRuby/Rails

Hello and sorry for possible repost,

I am newbie using latest Netbeans, JRuby/Rails… under Netbeans, in a
new Ruby Application, this code works:

require ‘java’
Dir[“jars/*.jar”].each { |jar| require jar };
import ‘iControl.Interfaces’
b=Interfaces.new()

I need to do the same in a Rails app… so I start new Rails project,
and in a controller I do:

require ‘java’
Dir[“lib/jars/*.jar”].each { |jar| require jar };
import ‘iControl.Interfaces’
class SayController < ApplicationController
def hello
b=Interfaces.new()
end
end

This gives error: uninitialized constant SayController::Interfaces

Can someone tell me what’s the proper way to get this working?
Thank you very much.
Mohamed.


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

On Wed, Jan 21, 2009 at 5:00 AM, Mohamed L. [email protected]
wrote:

Hello and sorry for possible repost,

No problem!

I am newbie using latest Netbeans, JRuby/Rails… under Netbeans, in a
new Ruby Application, this code works:

require ‘java’
Dir[“jars/*.jar”].each { |jar| require jar };
import ‘iControl.Interfaces’
b=Interfaces.new()

I need to do the same in a Rails app… so I start new Rails project,
and in a controller I do:

A couple things to try.

require ‘java’
Dir[“lib/jars/*.jar”].each { |jar| require jar };

Using relative paths here could be an issue, you might wish to convert
to an expression like Dir[File.join(RAILS_ROOT, “lib”, “jars”) +
“*.jar”] etc.

import ‘iControl.Interfaces’
class SayController < ApplicationController
def hello
b=Interfaces.new()

See if it works as ‘::Interfaces’. Sometimes Rails’ const_missing
dependency mechanism skews the constant lookup rules.

end
end

This gives error: uninitialized constant SayController::Interfaces

Can someone tell me what’s the proper way to get this working?

/Nick


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Thanks Nick… I tried this code, to no avail:

jars=""
Dir[File.join(RAILS_ROOT, “lib”, “jars”) +"/*.jar"].each { |jar|
jars+=jar+" "}

require ‘java’
Dir[File.join(RAILS_ROOT, “lib”, “jars”) +"/*.jar"].each { |jar| require
jar };
import ‘iControl.Interfaces’

class SayController < ApplicationController
def hello
@cur_dir = Dir.getwd
b=Interfaces.new()
init_result=b.initialize(“10.1.1.245”,443,“admin”,“admin”)
t=b.getSystemSystemInfo()
@bigip_version = t.get_version()
end
end

Using debugging session, I can see the paths are all correct for jar
files… but still hit same error, even using b=::Interfaces.new()

NameError (uninitialized constant SayController::Interfaces):
H:/NetBeans
6.5/ruby2/jruby-1.1.4/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:102:in
const_missing' /app/controllers/say_controller.rb:12:inhello’
H:/NetBeans
6.5/ruby2/jruby-1.1.4/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/base.rb:1253:in
perform_action' H:/NetBeans 6.5/ruby2/jruby-1.1.4/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/filters.rb:617:incall_filters’
H:/NetBeans
6.5/ruby2/jruby-1.1.4/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/filters.rb:610:in
perform_action_with_filters' H:/NetBeans 6.5/ruby2/jruby-1.1.4/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/benchmarking.rb:68:inperform_action_with_benchmark’
H:/NetBeans 6.5/ruby2/jruby-1.1.4/lib/ruby/1.8/benchmark.rb:293:in
measure' H:/NetBeans 6.5/ruby2/jruby-1.1.4/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/benchmarking.rb:68:inperform_action_with_benchmark’
H:/NetBeans
6.5/ruby2/jruby-1.1.4/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/rescue.rb:136:in
perform_action_with_rescue' H:/NetBeans 6.5/ruby2/jruby-1.1.4/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/caching/sql_cache.rb:13:inperform_action_with_caching’
H:/NetBeans
6.5/ruby2/jruby-1.1.4/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/connection_adapters/abstract/query_cache.rb:34:in
cache' H:/NetBeans 6.5/ruby2/jruby-1.1.4/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/query_cache.rb:8:incache’
H:/NetBeans
6.5/ruby2/jruby-1.1.4/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/caching/sql_cache.rb:12:in
perform_action_with_caching' H:/NetBeans 6.5/ruby2/jruby-1.1.4/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/base.rb:524:inprocess’
H:/NetBeans
6.5/ruby2/jruby-1.1.4/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/filters.rb:606:in
process_with_filters' H:/NetBeans 6.5/ruby2/jruby-1.1.4/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/session_management.rb:134:inprocess_with_session_management_support’
H:/NetBeans
6.5/ruby2/jruby-1.1.4/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/base.rb:392:in
process' H:/NetBeans 6.5/ruby2/jruby-1.1.4/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/dispatcher.rb:183:inhandle_request’
H:/NetBeans
6.5/ruby2/jruby-1.1.4/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/dispatcher.rb:110:in
dispatch_unlocked' H:/NetBeans 6.5/ruby2/jruby-1.1.4/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/dispatcher.rb:123:indispatch’
H:/NetBeans
6.5/ruby2/jruby-1.1.4/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/dispatcher.rb:122:in
dispatch' H:/NetBeans 6.5/ruby2/jruby-1.1.4/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/dispatcher.rb:132:indispatch_cgi’
H:/NetBeans
6.5/ruby2/jruby-1.1.4/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/dispatcher.rb:39:in
dispatch' H:/NetBeans 6.5/ruby2/jruby-1.1.4/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/webrick_server.rb:103:inhandle_dispatch’
H:/NetBeans
6.5/ruby2/jruby-1.1.4/lib/ruby/gems/1.8/gems/rails-2.2.2/lib/webrick_server.rb:74:in
service' H:/NetBeans 6.5/ruby2/jruby-1.1.4/lib/ruby/1.8/webrick/httpserver.rb:104:inservice’
H:/NetBeans
6.5/ruby2/jruby-1.1.4/lib/ruby/1.8/webrick/httpserver.rb:65:in run' H:/NetBeans 6.5/ruby2/jruby-1.1.4/lib/ruby/1.8/webrick/server.rb:173:instart_thread’
:1:in `start’

Rendered H:/NetBeans
6.5/ruby2/jruby-1.1.4/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/templates/rescues/_trace
(701.0ms)
Rendered H:/NetBeans
6.5/ruby2/jruby-1.1.4/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/templates/rescues/_request_and_response
(84.7ms)
Rendering H:/NetBeans
6.5/ruby2/jruby-1.1.4/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/templates/rescues/layout.erb
(internal_server_error)


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

On Wed, Jan 21, 2009 at 9:03 AM, Mohamed L. [email protected]
wrote:

class SayController < ApplicationController
files… but still hit same error, even using b=::Interfaces.new()

NameError (uninitialized constant SayController::Interfaces):

Did you get “uninitialized constant Interfaces” when running with the
::Interfaces version? If not, something’s not right.

Can you get the interfaces constant to load in a script/console session?

/Nick

H:/NetBeans
6.5/ruby2/jruby-1.1.4/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/rescue.rb:136:in
H:/NetBeans
`process_with_session_management_support’
6.5/ruby2/jruby-1.1.4/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/dispatcher.rb:123:in
H:/NetBeans
H:/NetBeans
Rendering H:/NetBeans
6.5/ruby2/jruby-1.1.4/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/templates/rescues/layout.erb
(internal_server_error)


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

With ::Interfaces.new() I get:

uninitialized constant Interfaces

With Interfaces.new() I get:

uninitialized constant SayController::Interfaces

Under IRB, inside NetBeans, this works:

require ‘java’
=> false

Dir[“lib/jars/*.jar”].each { |jar| require jar }
=> [“lib/jars/axis.jar”, “lib/jars/commons-discovery-0.2.jar”,
“lib/jars/commons-logging-1.0.4.jar”, “lib/jars/iControl.jar”,
“lib/jars/jaxrpc.jar”, “lib/jars/mailapi.jar”,
“lib/jars/wsdl4j-1.5.1.jar”]

import ‘iControl.Interfaces’
=> [“iControl.Interfaces”]

b=Interfaces.new()
=> #<Java::IControl::Interfaces:0x44091520
@java_object=iControl.Interfaces@304a0ac5>

But IRB does not load in the context of Rails, right?
Mohamed.


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

On Wed, Jan 21, 2009 at 10:30 AM, Mohamed L. [email protected]
wrote:

=> #<Java::IControl::Interfaces:0x44091520
@java_object=iControl.Interfaces@304a0ac5>

But IRB does not load in the context of Rails, right?

No, but that’s why I suggested using script/console, because it loads
Rails in the IRB environment. Maybe something Rails is loading is
messing with your load path or environment.

/Nick


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

You’re right Nick, something is not right under Rails, please see
bellow. any suggestions where to go from here?
Thanks a lot.

RAILS_ROOT
=> “E:/Documents and Settings/Administrator/My
Documents/NetBeansProjects/RailsApplication1”

require ‘java’
=> []

Dir[File.join(RAILS_ROOT, “lib”, “jars”) +"/*.jar"].each { |jar| require jar }
=> [“E:/Documents and Settings/Administrator/My
Documents/NetBeansProjects/RailsApplication1/lib/jars/axis.jar”,
“E:/Documents and Settings/Administr
r/My
Documents/NetBeansProjects/RailsApplication1/lib/jars/commons-discovery-0.2.jar”,
“E:/Documents and Settings/Administrator/My Documents/NetBeans
jects/RailsApplication1/lib/jars/commons-logging-1.0.4.jar”,
“E:/Documents and Settings/Administrator/My
Documents/NetBeansProjects/RailsApplication1
b/jars/iControl.jar”, “E:/Documents and Settings/Administrator/My
Documents/NetBeansProjects/RailsApplication1/lib/jars/jaxrpc.jar”,
“E:/Documents an
ettings/Administrator/My
Documents/NetBeansProjects/RailsApplication1/lib/jars/mailapi.jar”,
“E:/Documents and Settings/Administrator/My Documents/Ne
ansProjects/RailsApplication1/lib/jars/wsdl4j-1.5.1.jar”]

?> import ‘iControl.Interfaces’
=> [“iControl.Interfaces”]

b=Interfaces.new()
NameError: uninitialized constant Interfaces
from H:/NetBeans
6.5/ruby2/jruby-1.1.4/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:445:in
load_missing_con nt' from H:/NetBeans 6.5/ruby2/jruby-1.1.4/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:77:inconst_missing_wit
ependencies’
from H:/NetBeans
6.5/ruby2/jruby-1.1.4/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:89:in
const_missing' from (irb):7:inbinding’
from H:/NetBeans
6.5/ruby2/jruby-1.1.4/lib/ruby/1.8/irb.rb:150:in eval_input' from H:/NetBeans 6.5/ruby2/jruby-1.1.4/lib/ruby/1.8/irb.rb:259:insignal_status’
from H:/NetBeans
6.5/ruby2/jruby-1.1.4/lib/ruby/1.8/irb.rb:147:in eval_input' from H:/NetBeans 6.5/ruby2/jruby-1.1.4/lib/ruby/1.8/irb.rb:146:ineval_input’
from H:/NetBeans 6.5/ruby2/jruby-1.1.4/lib/ruby/1.8/irb.rb:70:in
start' from H:/NetBeans 6.5/ruby2/jruby-1.1.4/lib/ruby/1.8/irb.rb:69:incatch’
from H:/NetBeans 6.5/ruby2/jruby-1.1.4/lib/ruby/1.8/irb.rb:69:in
`start’
from H:/NetBeans 6.5/ruby2/jruby-1.1.4\bin\jirb:19


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email