为什么 Fantom 找不到 jar 中的资源?
我最近开始使用 Fantom。我有一个包含资源(在本例中为 svg 图像)的 jar 文件。我可以很好地使用 jar 中的类,但资源不会加载: Thread.currentThread().getContextClassLoader().getResourceAsStream("name")
returns null
。当我在纯 Java 上下文中使用这个完全相同的 jar 时,它可以很好地找到资源。
任何有关如何调试甚至解决此问题的建议将不胜感激。
I've recently gotten started using Fantom. I've got a jar file that contains a resource (svg image, in this case). I can use the classes from the jar just fine, but the resource won't load: Thread.currentThread().getContextClassLoader().getResourceAsStream("name")
returns null
. When I use this exact same jar in a Java-only context, it can find the resource just fine.
Any suggestions on how to debug or even solve this issue would be much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
它必须在罐子里吗?如果将其直接插入 Pod 中,则可以使用访问文件,如下所示:
Does it have to be in a Jar? If you stick it directly in your Pod, you can use access files like this:
错误的部分是
Thread.currentThread().getContextClassLoader()
Java:
AnyClassFromJar.class.getClassLoader()
有效Fantom:
Class.forName("AnyClassFromJar") .getClassLoader()
应该可以工作The wrong part is
Thread.currentThread().getContextClassLoader()
Java:
AnyClassFromJar.class.getClassLoader()
worksFantom:
Class.forName("AnyClassFromJar").getClassLoader()
should work如果我没记错的话,
.jar
文件无法访问资源,但由于.jar
文件只不过是具有精美扩展名的 Zip 文件,您可以像这样打开它们。这是我的示例文件夹结构(但任何结构都可以)。
然后您像这样打开
testOpen.jar
:编辑:在 Fantom 板上对此进行了讨论,看来这个示例应该可行。
If I recall correctly,
.jar
files can't be accessed for resoruces but since.jar
files are nothing more than Zip files with fancy extension you can open them like that.Here is my folder structure for the example (but any structure will do).
And you open the
testOpen.jar
like this:EDIT: Having a discussion about this on Fantom boards it seems that this example should work.
尝试使用“/name”而不是“name”。这对我有用(用Java)。
Try '/name' instead of 'name'. That works for me (in Java).