How to get an URL for a resource directory when using OneJar?

淺唱寂寞╮ 提交于 2019-12-11 09:13:51

问题


I need to pass the root "something" to a piece of code working with resources. I know that this "something" can't be a file, since this doesn't work in a JAR. So I'm passing an URL.

Before I started with OneJar I transformed an URL like

file:/some/path!/foo/bar/MyUrlSupplier.class

into

file:/some/path!/foo/images/

and used this as the root URL. With OneJar I'm getting

onejar:foo.bar.MyUrlSupplier.class

and transforming it into

onejar:foo.images

but whatever I do with this URL, nothing works. The best I get is this stacktrace caused by loading new ImageIcon(url):

Uncaught error fetching image:
java.lang.ClassCastException: sun.misc.Launcher$AppClassLoader cannot be cast to com.simontuffs.onejar.JarClassLoader
    at com.simontuffs.onejar.JarClassLoader.getByteStream(JarClassLoader.java:753)
    at com.simontuffs.onejar.Handler$1.getInputStream(Handler.java:50)
    at sun.awt.image.URLImageSource.getDecoder(URLImageSource.java:126)
    at sun.awt.image.InputStreamImageSource.doFetch(InputStreamImageSource.java:263)
    at sun.awt.image.ImageFetcher.fetchloop(ImageFetcher.java:205)
    at sun.awt.image.ImageFetcher.run(ImageFetcher.java:169)

来源:https://stackoverflow.com/questions/21361931/how-to-get-an-url-for-a-resource-directory-when-using-onejar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!