从JRuby中的jar文件加载图像

时间:2012-11-16 04:19:00

标签: jar jruby

icon.png位于myapp.jar

DANIELs-MacBook-Air-2:jrubyScreenshot dani [master] $ jar -tf myapp.jar | tail
....
icon.png

我该如何加载它? 这将返回nil

f = java.lang.Object.new
image = java.awt.Toolkit::default_toolkit.get_image(f.java_class.resource("icon.png"))

解决方案是:

 f = java.lang.Object.new
 url = f.java_class.resource("/icon.png")

1 个答案:

答案 0 :(得分:1)

也许是CLASSPATH

> jruby -J-classpath myapp.jar test.rb

include Java

f = java.lang.Object.new
url = f.java_class.resource("/icon.png")
image = java.awt.Toolkit::default_toolkit.get_image(url)
puts image