Getting resources from jar in a java webstart application

懵懂的女人 提交于 2019-12-02 00:31:11
public static void main(String[] args) throws IOException, URISyntaxException {
  ClassLoader loader = MyClass.class.getClassLoader();
  String r = "resourceName";
  URL url = loader.getResource(r);
  System.out.println(url!=null);
  InputStream in = url.openStream();
  System.out.println(in!=null);
}

Ok - so the problem was that I was trying to access directory of resources (i.e. from the example in my question, resourceName is a directory of resource files).

Whilst it is possible to access resources in this way in most environments (e.g. in an IDE), it is not possible when running from Java webstart.

I found this page particularly helpful: http://lopica.sourceforge.net/faq.html#listresources

...and have followed that approach to make a catalogue of resources, that I can then iterate through to get the relevant resources.

you needy to add the class path in your manifest file

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