I spent a little time trying to get this to work and they are doing
something unfun with class loaders
Here is code which almost works:
----- code ----
require ‘java’
java_import java.awt.Font
java_import org.apache.pivot.wtk.DesktopApplicationContext
java_import org.apache.pivot.wtk.HorizontalAlignment
java_import org.apache.pivot.wtk.VerticalAlignment
class HelloJava
include org.apache.pivot.wtk.Application
def startup(display, properties)
label = org.apache.pivot.wtk.Label.new.tap do |l|
l.text = “Nom Nom Nom!”
l.styles.tap do |s|
s.put(“font”, Font.new(“Arial”, Font::BOLD, 24))
s.put(“color”, java.awt.Color::RED)
s.put(“horizontalAlignment”, HorizontalAlignment::CENTER)
s.put(“verticalAlignment”, VerticalAlignment::CENTER)
end
end
@window = org.apache.pivot.wtk.Window.new.tap do |w|
w.content = label
w.title = "HEH HEH HEH!"
w.maximized = true
w.open(display);
end
end
def shutdown(optional)
window.close if @window
false
end
def suspend; end
def resume; end
end
HelloJava.new # Unfortunately Java interface not really implemented
until first
# construction
DesktopApplicationContext.main(HelloJava.to_java(java.lang.Class),
[].to_java(:string))
----- code ----
Invocation:
CLASSPATH=lib/pivot-core-1.4.jar:lib/pivot-wtk-1.4.jar:lib/pivot-wtk-terra-1.4.jar:.
jruby hello.rb
---- The error —
java.lang.ClassNotFoundException: HelloJava_591025772
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:315)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:330)
at java.lang.ClassLoader.loadClass(ClassLoader.java:250)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:398)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at
org.apache.pivot.wtk.DesktopApplicationContext$HostFrame.processWindowEvent(Unknown
Source)
at java.awt.Window.processEvent(Window.java:1820)
at java.awt.Component.dispatchEventImpl(Component.java:4714)
at java.awt.Container.dispatchEventImpl(Container.java:2143)
at java.awt.Window.dispatchEventImpl(Window.java:2475)
at java.awt.Component.dispatchEvent(Component.java:4544)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:635)
at
java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296)
at
java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)
at
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201)
at
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)
at
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
So wtk eventing appears to be doing a Class.forName on HelloJava for
some reason (perhaps to not store and pass around original class
reference), and it cannot find it since our classloader loaded it and
not their’s.
If you can tell pivot to use our classloader somehow or get some help
on the pivot side to better understand the issue then perhaps we can
help more. You could use jrubyc --java to generate a Java stub class
as a workaround (then it can load that Java class in its classloader),
but it seems like the above code should work in an ideal world.
Maybe someone on this list may have an idea…
-Tom
On Mon, Apr 19, 2010 at 8:45 AM, Chris D. [email protected] wrote:
Chris
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email
–
blog: http://blog.enebo.com twitter: tom_enebo
mail: [email protected]
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email