0 Replies Latest reply on Nov 3, 2011 12:43 PM by 897576

    Java Web Start (JNLP) getResource return null.

      I have a Java Web Start Swing application and with the Java version 1.6.0_u27.
      same code run from jdk1.1.8 to jdk 1.6, more then 10 customers it's work fine, java web start only run on jdk 1.4.0 and jdk 1.5.0.
      just migrate one customer from Java version 1.5.0_u6 to 1.6.0_u27.
      sometimes, the getResource will return null, when system return null, then system cannot get any other resource, always return null.
      It only happen in Java web start environment, work fine in command line (java/javaw), and same as the WebStart loses resources post,
      "Unfortunately this cannot be reproduced easily. Sometimes this happens after some minutes, sometimes the application can be used for days without problems.",
      note. all of my resource files put in the same jar file, one resource file in that jar get fail, all files will be fail.
      after I get the url, I will use new BufferedInputStream(url.openStream()); to retrieve data, never use the File object.
      for example, get resource from "/path/a1.xml", "/path/a2.xml"....... 30 minutes pass, get same file "/path/a1.xml" will return null, then all resource will return null.

      URL url = getClass().getResource(s);
      if(url == null) {
      System.out.println(getClass().getResourceAsStream(s)); // also null, log only
      // if the url == null, the following retrieve will be null
      url = Thread.currentThread().getContextClassLoader().getResource(s);
      if(url == null){
      System.out.println(Thread.currentThread().getContextClassLoader().getResourceAsStream(s)); // also null, log only
      ClassLoader loader = getClass().getClassLoader();
      if(loader == null){
      loader = ClassLoader.getSystemClassLoader();
      if(loader != null) {
      System.out.println(loader.getResourceAsStream(s)); // also null, log only
      url = loader.getResource(s);
      if(url == null) {
      System.out.println("URL resource still can not found!!" + s);

      Edited by: M. Jwo on 2011/11/3 上午 5:40