I'm not sure if I'm missing something obvious here. I'm attempting to
adapt code of the following form:
Application.class.getResource("config/application.conf");
or
getClass().getResource("/config/application.conf");
but am having problems. More specifically, I can't seem to find the
getResource() method from JRuby. I've tried:
Application.class.getResource()
Application.getClass.getResource()
Application.java_class.getResource()
and none of these seem to find getResource(). This is on JRuby trunk.
What am I missing?
Thanks.
---------------------------------------------------------------------
To unsubscribe from this list please visit:
http://xircles.codehaus.org/manage_email
on 08.10.2007 22:38
on 08.10.2007 23:00
I recently ran into this same issue, but I was able to get what I
needed using something like:
jc = Java::JavaClass.for_name("classname")
jc.java_class.java_method("getResource").invoke(jc)
I was also a bit confused why none of the things you tried below
worked, but I never got around to posting.
Related to this, is there a reason why JRuby doesn't set the current
Java thread's contextClassLoader to the JRubyClassLoader? This caused
all kinds of problems for me because I was trying to use the Spring's
ClassPathXmlApplicationContext, but it seems that internally, Spring
keeps trying to load stuff with the Thread's contextClassLoader so
resources that I had added to the $CLASSPATH were not being found. I
wound up with something like:
load_from_class = Java::JavaClass.for_name
("org.springframework.context.support.ClassPathXmlApplicationContext")
class_loader = load_from_class.java_class.java_method
("getClassLoader").invoke(load_from_class)
JThread.currentThread().setContextClassLoader(class_loader)
@@app_context = ClassPathXmlApplicationContext.new(paths.to_java
(:string), ClassPathXmlApplicationContext.java_class)
I'm still not sure if that's going to come back and bite me eventually.
-lenny
On Oct 8, 2007, at 4:38 PM, Nolan Darilek wrote:
> getResource() method from JRuby. I've tried:
>
> ---------------------------------------------------------------------
> 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
on 09.10.2007 18:25
On Oct 8, 2007, at 3:59 PM, Lenny Marks wrote: > jc = Java::JavaClass.for_name("classname") > jc.java_class.java_method("getResource").invoke(jc) > > Ewww. Much as I'm looking forward to writing future apps in Ruby, > I'm not looking forward to having to do *that*. :/ I use the > getClass().getResource() pattern fairly often. Is this a bug in the Java integration? Has it already been filed, or should I? Not sure why self.class.getResource shouldn't work for Ruby subclasses of Java classes. Maybe self.java_class.getResource() at worst. --------------------------------------------------------------------- To unsubscribe from this list please visit: http://xircles.codehaus.org/manage_email
on 09.10.2007 19:13
I've seen the same behavior; get_resource always returns nil when I could run the same thing in Java and have it work. I thought it might be a bug, but never got around to posting it here. My intermediate solution was to make a pure Java class that did just the getResource part for me. But using something like self.java_class.get_resource does look better than what I did. I'm going to switch to that for now.