Closed efoxepstein closed 14 years ago
My usual approach is to stick to the convention of putting the foo.jar in a folder foo, placing that in a library folder. Then in foo.rb load the library 'foo', works for me. The rp5 does the require 'java' for you.
Tried that. Exact same error. Tried "load_library 'foo'; import 'foo'". Any ideas?
class Test < Processing::App
load_library :foo
include_package "foo"
def setup
fred = Java::Foo::Bar.new()
fred.baz()
end
end
Worked for me!
Or if you really wanted a class method:-
class Test < Processing::App
load_library :foo
include_package "foo"
def setup
Java::Foo::Bar::baz()
end
end
Where my baz method was System.out.println("baz");
baz got printed
Here is an exact transcript from my Terminal:
$ cat Bar.java
package foo;
public class Bar {
public Bar(){
System.out.println("Working");
}
}
$ javac Bar.java
$ jar cvf library/foo/foo.jar Bar.class
added manifest
adding: Bar.class(in = 344) (out= 258)(deflated 25%)
$ cat foo.rb
load_library :foo
include_package 'foo'
def setup
Java::Foo::Bar.new
end
$ rp5 run foo.rb
Exception in thread "Animation Thread" :1:in `const_missing': cannot load Java class foo.Bar (NameError)
from foo.rb:6:in `setup'
from :1
...internal jruby stack elided...
from #<Class:01x2eb80f1c>.const_missing(foo.rb:6)
from Sketch.setup(:1)
from (unknown).(unknown)(:1)
Am I packaging things up wrong? Any ideas on how to debug?
I don't know but I did javac foo/Bar.java? But it wouldn't compile otherwise? Wait a minute its the archiving thats the problem:- jar cvf foo.jar foo (its the folder as source....)
Was your Bar.java inside of a folder called foo
? Mine was in the working directory. How did you jar yours up? Could you show me your Java file and all of the commands you executed?
Thanks so much!
package foo;
public class Bar{
public Bar(){}
public static void baz(){
System.out.println("baz");
}
}
That was the class method version, the other should be obvious yes in a folder foo.
I think we might have just got crossed messages hope thats OK.
Yeah, that's it. I had to include the folder in the jar. I wasn't aware of that. Thanks so much!
Given this
foo.rb
:This works:
This fails:
with:
Is rp doing something funky with
require
?