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

67dd904963ce73ee90f5f6620a542aeb?d=identicon&s=25 Shrikrishna Khose (krishnaji)
on 2014-03-11 23:19
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:in `get_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:in `map'
  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:in `evaluate'
  from org/jruby/RubyKernel.java:1121:in `eval'
  from org/jruby/RubyKernel.java:1521:in `loop'
  from org/jruby/RubyKernel.java:1284:in `catch'
  from org/jruby/RubyKernel.java:1284:in `catch'
  from /Users/MacUser/.rbenv/versions/jruby-1.7.11/bin/irb:13:in
`(root)'

Thank you for your time.
Caa2df9372ffa0a9e95b2bab1e8fea34?d=identicon&s=25 Karol Bucek (Guest)
on 2014-03-12 09:39
(Received via mailing list)
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.
67dd904963ce73ee90f5f6620a542aeb?d=identicon&s=25 Shrikrishna Khose (krishnaji)
on 2014-03-15 12:25
Thank you !
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.