ZeroTurnaround Support Forum » JRebel Support

JavaRebel doesn't see Netbeans module resources(images)

(9 posts)
  • Started 7 months ago by hohercak
  • Latest reply from hohercak

  1. hohercak

    Member
    Posts: 6

    I am using JavaRebel 2.2.1 with NetBeans Platform 6.5. Class reloading works fine but probably it doesn’t see resources (images, etc..) Images are in netbeans module target folder which is monitored. The access code is new javax.swing.ImageIcon(getClass().getResource("/icons/email48.png")). In jrebel.log appears:
    [1264003724975] sun.misc.Launcher$ExtClassLoader@f4a24a searching for resource 'icons/email48.png'.
    [1264003724975] sun.misc.Launcher$ExtClassLoader@f4a24a not found resource 'icons/email48.png'.
    [1264003724975] sun.misc.Launcher$AppClassLoader@13f5d07 searching for resource 'icons/email48.png'.
    [1264003724975] sun.misc.Launcher$AppClassLoader@13f5d07 not found resource 'icons/email48.png'.

    But for netbeans module resources is responsible org.netbeans.StandardModule$OneModuleClassLoader. Example of class reloading log:
    [1264003724834] org.netbeans.StandardModule$OneModuleClassLoader@17d80e9 loaded instrumented class 'cz.xxxx‘

    NetBeans module classloader initialization
    [1264003427055] Rebel runtime under 'org.netbeans.StandardModule$OneModuleClassLoader@17d80e9' created.
    [1264003427055] Rebel runtime 'org.netbeans.StandardModule$OneModuleClassLoader@17d80e9' is using native source 'org.zeroturnaround.javarebel.integration.generic.FindResourceClassResourceSource@1d5ebc'.
    [1264003427055] Rebel runtime 'org.netbeans.StandardModule$OneModuleClassLoader@17d80e9' class loader toString(): org.netbeans.StandardModule$OneModuleClassLoader@17d80e9[cz.xxxx]
    [1264003427055] The following class loader parents found: org.netbeans.StandardModule$OneModuleClassLoader@17d80e9, sun.misc.Launcher$AppClassLoader@13f5d07, sun.misc.Launcher$ExtClassLoader@f4a24a
    [1264003427289] Class Loader 'org.netbeans.StandardModule$OneModuleClassLoader@17d80e9' fallback mode is set to 'default'.
    [1264003427289] Class Loader 'org.netbeans.StandardModule$OneModuleClassLoader@17d80e9' attached to the source 'MultiResourceSource [MultiResourceSource [Dir [C:\xxx...

    Posted 7 months ago #
  2. lauri

    Member
    Posts: 482

    Should be fixed in nightly build http://www.zeroturnaround.com/nightly-build/jrebel-nightly-dev.zip

    Posted 7 months ago #
  3. hohercak

    Member
    Posts: 6

    Now it throws:

    [1264180608632] org.zeroturnaround.bundled.javassist.NotFoundException: findResources(..) is not found in org.netbeans.JarClassLoader
    at org.zeroturnaround.bundled.javassist.CtClassType.getDeclaredMethod(JRebel:1128)
    at org.zeroturnaround.javarebel.integration.netbeans.NetbeansJarClassLoaderCBP.process(JRebel:118)
    at org.zeroturnaround.javarebel.integration.support.JavassistClassBytecodeProcessor.process(JRebel:32)
    at com.zeroturnaround.javarebel.SDKIntegrationImpl.runBytecodeProcessors(JRebel:231)
    at com.zeroturnaround.javarebel.java4.RuntimeInstall.transform(JRebel:39)
    at java.lang.ClassLoader.defineClass(ClassLoader.java)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
    at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
    at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
    at org.netbeans.MainImpl.execute(MainImpl.java:180)
    at org.netbeans.MainImpl.main(MainImpl.java:76)
    at org.netbeans.Main.main(Main.java:75)

    I have found the method public Enumeration findResources(String s) in NetBeans platform 6.8 but not in 6.5. In 6.5 is very similar method protected Enumeration simpleFindResources(String name). Method body exactly match but this method is protected.

    Posted 7 months ago #
  4. lauri

    Member
    Posts: 482

    @hohercak
    looks like i made a small typo in the patch, will fix on monday.

    Posted 7 months ago #
  5. lauri

    Member
    Posts: 482

    Fixed in nightly build http://www.zeroturnaround.com/nightly-build/jrebel-nightly-dev.zip

    Posted 7 months ago #
  6. hohercak

    Member
    Posts: 6

    Now it works. But resources are somewhere cached. Example:

    I have a picture named pic.png, in app jar there is a picture of a HOUSE, on the other hand in a monitored dir there is a picture of a DOG.

    1) Now I start the app and jrebel loads a picture of the DOG. That is correct.
    2) I remove pic.png from the monitored folder, close and open a form with pic.png. Jrebel loads a picture with the HOUSE. That is correct.
    3) I copy new pic.png with a picture of a CAR into the monitored folder, close and open a form. In jrebel the log file appears loading pic.png from the monitored folder but the form shows the picture of the DOG, that is not correct.

    The picture loadig code is new javax.swing.ImageIcon(getClass().getResource("/icons/pic.png"))

    Maybe following log record helps. It is right behind resource loading.

    [1264431381678] org.netbeans.StandardModule$OneModuleClassLoader@63d12a6 searching for class 'org.netbeans.modules.masterfs.filebasedfs.fileobjects.FolderObj$FolderChildrenCache'.

    Posted 7 months ago #
  7. hohercak

    Member
    Posts: 6

    I have tried load pic.png using getClass().getResourceAsStream(“/icons/pic.png“) and it worked correctly. The loading code follows:

    InputStream resourceAsStream = getClass().getResourceAsStream("/icons/pic.png");
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream(4096);
    byte[] bytes = new byte[512];
    int readBytes;
    
    try {
      while ((readBytes = resourceAsStream.read(bytes)) > 0) {
      outputStream.write(bytes, 0, readBytes);
    
      byte[] byteData = outputStream.toByteArray();
      setBannerNormalIcon(new javax.swing.ImageIcon(byteData));
    catch (...
    Posted 7 months ago #
  8. lauri

    Member
    Posts: 482

    javax.swing.ImageIcon(java.net.URL) calls java.awt.Toolkit#getImage(java.net.URL) consult the javadoc of this method for a possible workaround

    Posted 7 months ago #
  9. hohercak

    Member
    Posts: 6

    The code setXxxIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/pic.png"))) is generated by the Netbeans GUI designer and the code is locked for changes (in NetBeans IDE). Any changes are uncomfortable.

    Searching for references to ALL ImageIcons on a form to call java.awt.Image#flush() is not optimal solution (Images added to form after searching). Adding any code to the app is uncomfortable.

    Better workaround is to manage one concrete image file in time of reloading with the usage of Java Reflection:

    Field declaredField = SunToolkit.class.getDeclaredField("imgCache");
    declaredField.setAccessible(true); // package private
    SoftCache imgCache = (SoftCache) declaredField.get(null); // static field
    imgCache.remove(URL);

    You know which URL to remove in getClass().getResource(URL) in time of reloading.

    Is there any possibility to add this code to JRebel?

    Posted 7 months ago #

RSS feed for this topic

Reply

(required)

(required)

(optional)

(required)

Allowed markup: a blockquote code em strong ul ol li.
Put code in between `backticks`.

Olark Livehelp