NameError: cannot load Java class com.foo.bar

Hello,
just started learning jRuby and tried to create a jar and use it but
getting following error when I java_import ‘packagename’

NameError: cannot load Java class com.foo.bar.

Could anyone point me in right direction.

cat /Users/MacUser/jruby_projects/foo/bin/my_foo.rb

java_package ‘com.foo.bar’
class Foo
def bar(a, b)
puts a + b
end
end


from foo folder I run
warble jar

then foo/foo.jar

irb(main):001:0> require ‘foo.jar’
=> true

irb(main):004:0> $CLASSPATH
=>
[“file:/Users/MacUser/.rbenv/versions/jruby-1.7.11/lib/ruby/shared/readline/jline-2.11.jar”,
“file:/Users/MacUser/.rbenv/versions/jruby-1.7.11/lib/ruby/shared/readline/readline.jar”,
“file:/Users/MacUser/jruby_projects/foo/foo.jar”]

irb(main):003:0> java_import ‘com.foo.bar’
NameError: cannot load Java class com.foo.bar
from org/jruby/javasupport/JavaClass.java:1250:in for_name' from org/jruby/javasupport/JavaUtilities.java:34:inget_proxy_class’
from
file:/Users/MacUser/.rbenv/versions/jruby-1.7.11/lib/jruby.jar!/jruby/java/core_ext/object.rb:26:in
java_import' from org/jruby/RubyArray.java:2409:inmap’
from
file:/Users/MacUser/.rbenv/versions/jruby-1.7.11/lib/jruby.jar!/jruby/java/core_ext/object.rb:22:in
java_import' from (irb):3:inevaluate’
from org/jruby/RubyKernel.java:1121:in eval' from org/jruby/RubyKernel.java:1521:inloop’
from org/jruby/RubyKernel.java:1284:in catch' from org/jruby/RubyKernel.java:1284:incatch’
from /Users/MacUser/.rbenv/versions/jruby-1.7.11/bin/irb:13:in
`(root)’

Thank you for your time.

just read the error:

NameError: cannot load Java class com.foo.bar
com.foo.bar.class is likely not in the package . treat java_import like
Java’s import - import classes not packages.

for simple failures (esp. if you’re getting started) may I advise to try
out http://stackoverflow.com/questions/tagged/jruby

K.

Thank you !

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs