facebook

getResource doesn’t work in design mode

  1. MyEclipse Archived
  2.  > 
  3. Matisse/Swing UI Development
Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #325226 Reply

    Lofi
    Participant

    When we use MyClass.class.getClassLoader().getResource( “/myproject”) then this returns null in Matisse design mode. The problem seems to be that in design mode the classloader is com.genuitec.eclipse.dehory.util.MatisseClassLoader.

    Is there a special magic that you need to apply to your resource path in order to get a resource during design mode? The files are there. Everything works in production mode. But for some reason the Matisse classloader doesn’t find any project related resources.

    Thank you very much for your help!

    #325265 Reply

    support-tony
    Keymaster

    Lofi,

    Could you explain where you are using the getResource method and when you are trying to run that piece of code? The Matisse editor is just for designing the form.

    If there are screen snapshots that you think might be helpful in our understanding your problem, please attach them. Also, please attach details of your installation by going to MyEclipse->Installation Summary->Installation details and attaching the result.

    #325279 Reply

    Lofi
    Participant

    Thank you for your reply.

    We are using getResource in order to get the absolute path to the resource bundle strings for our swing application.

    Example project:

    MYPROJECT\src\game\myclasses
    MYPROJECT\src\game\mybundles
    MYPROJECT\src\game\myicons

    In design mode we want to resolve e. g. “en.label.income=Income” from a file in .\mybundles and want to see “Income” in the UI and not “en.label.income”. Another example are the locations and the display of icons during design mode.

    Basically with getResource( “/game/”) we want to get the absolute path, eg c:\project\MYPROJECT\src\game.

    It all works during runtime, but not in design mode. I wonder why that is. All we can see is that the MatisseClassLoader can’t resolve our folder /game/.

    Here’s the requested data:

    *** Date: 
    Montag, 16. April 2012 14:29 Uhr MESZ
    
    ** System properties:
    OS=WindowsVista
    OS version=6.1.0
    Java version=1.6.0_13
    
    
    *** MyEclipse details:
    MyEclipse Enterprise Workbench
    Version: 10.0
    Build id: 10.0-20111028
    
    
    *** Eclipse details:
    MyEclipse Enterprise Workbench
    
    Version: 10.0
    Build id: 10.0-20111028
    
    Eclipse startup command=-os
    win32
    -ws
    win32
    -arch
    x86_64
    -showsplash
    -launcher
    C:\project\MyEclipse-10.0\MyEclipse 10\myeclipse.exe
    -name
    Myeclipse
    --launcher.library
    C:\project\MyEclipse-10.0\MyEclipse 10\../Common/plugins/org.eclipse.equinox.launcher.i18n.win32.win32.x86_64_3.2.0.v201103301700\eclipse_3215.dll
    -startup
    C:\project\MyEclipse-10.0\MyEclipse 10\../Common/plugins/org.eclipse.equinox.launcher_1.2.0.v20110502.jar
    -exitdata
    988_58
    -install
    C:\project\MyEclipse-10.0\MyEclipse 10
    -configuration
    C:\project\MyEclipse-10.0\MyEclipse 10\configuration
    -data
    C:\project\workspace
    -vm
    C:\project\MyEclipse-10.0\Common\binary\com.sun.java.jdk.win32.x86_64_1.6.0.013\bin\javaw.exe
    
    #325302 Reply

    support-tony
    Keymaster

    Lofi,

    Thanks for the extra details but I’m still not exactly sure how you’re trying to do this. However, I can confirm that there is no specific string internationalization support in Matisse for MyEclipse. Such support is in the Swing Designer for MyEclipse, which you might want to consider switching to, if possible. This is available from the the Dashboard in the MyEclipse Configuration Center, if you want to give it a go.

    #325344 Reply

    Lofi
    Participant

    Thank you, but my question was not regarding internationalization, it’s about the classloader and resources. Let me rephrase with a very basic example. Let’s say I have a custom form with the following code (relevant parts are the system.out.println in the constructor) which is put on a frame:

    
    package games;
    
    public class MyPanel extends javax.swing.JPanel {
    
      /** Creates new form MyPanel */
      public MyPanel() {
        
        System.out.println( "Classloader: " + MyFrame.class.getClassLoader());
        System.out.println( "Resource: " + MyFrame.class.getClassLoader().getResource( "games"));
        
        initComponents();
      }
    
      /** This method is called from within the constructor to
       * initialize the form.
       * WARNING: Do NOT modify this code. The content of this method is
       * always regenerated by the Form Editor.
       */
      //GEN-BEGIN:initComponents
      // <editor-fold defaultstate="collapsed" desc="Generated Code">
      private void initComponents() {
    
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout( this);
        this.setLayout( layout);
        layout.setHorizontalGroup( layout.createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING).addGap( 0, 400, Short.MAX_VALUE));
        layout.setVerticalGroup( layout.createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING).addGap( 0, 300, Short.MAX_VALUE));
      }// </editor-fold>
      //GEN-END:initComponents
    
      //GEN-BEGIN:variables
      // Variables declaration - do not modify
      // End of variables declaration//GEN-END:variables
    
    }

    When I execute the frame’s class, then I get in the console:

    Classloader: sun.misc.Launcher$AppClassLoader@11b86e7
    Resource: file:/C:/projects/workspace/MYPROJECT/build/classes/games
    

    When I open the form in Matisse in design mode, then I get in MyEclipse’s explorer-console.log:

    Classloader: com.genuitec.eclipse.dehory.util.MatisseClassLoader@6a760dde
    Resource: null

    I want the resource and not null. The problem is that the MatisseClassLoader obviously doesn’t know anything about “games”. The question is: why and how can I get it to resolve the resource path correctly.

    Thank you very much for your help! 🙂

    #325362 Reply

    support-tony
    Keymaster

    I’m not sure how the Matisse editor loads classes in the situation you described. I’ve asked a developer to have a look at it; hopefully, he can come up with something.

    However, I wasn’t able to replicate your situation and get no output in the explorer-console.log file, so I’m not sure it I’ve done something different from what you have. From my tests, the class isn’t loaded in the normal way, otherwise the code in the constructor would be executed.

    I suspect that the classes aren’t loaded in the normal way, during an edit session, so you could try adding a statement to figure out where the base directory is for edit-time class loading. Something like:

    System.out.println("Base class folder: " + MyFrame.class.getClassLoader().getResource("."));
    #325383 Reply

    Lofi
    Participant

    Thank you very much for forwarding this issue.

    Getting the resource “.”, i. e. your line delivers the same result: null.

    I think Matisse isn’t flushing the logs all the time. I had that as well occasionally that nothing was in the log. Then I put the custom component into a frame, closed and reopened the frame’s form and suddenly there were all missing log entries.

    That’s exactly what I need to do: Find the base directory for edit-time class loading. I hope your developer can come up with something.

    Thanks a lot for your help! 🙂

    #325395 Reply

    support-tony
    Keymaster

    Lofi,

    Thanks for the help on getting the system output to show up in that log file!

    The MatisseClassLoader will not find directories. You will have to look for an actual file. So, suppose you had a file “game/game.properties” your getResource statement would be:

    matisseClassLoader.getResource("game/game.properties")

    From that you can determine the game directory and work from there.

    Please let us know if this works for you.

    #325398 Reply

    Lofi
    Participant

    Hello,

    thank you, but this I already tried. In every possible form. With and without slashes. With an without subpaths and workspace and what not.

    It doesn’t work. Does it work for you?

    The only hack that worked so far is using an included library and get a resource from there. But that’s an ugly hack. e. g. if you include swing-layout-1.0.jar, then search for a package from there.

    Do you have any other ideas what may go wrong here?

    #325401 Reply

    support-tony
    Keymaster

    Lofi,

    That worked for me. But you still get null returned?

    I actually have the following file: src/game/bundles/my.properties (from some earlier work) and this gets copied to the output folder as bin/game/bundles/my.properties. When I look for “game/bundles/my.properties”, with getResource, it finds it in both the Matisse editor and at runtime.

    These are the relevant lines of code:

    ClassLoader matisseClassLoader = MyFrame.class.getClassLoader();
    System.out.println("Resource: " + matisseClassLoader.getResource("game/bundles/my.properties"));
    #325410 Reply

    Lofi
    Participant

    Hello support-tony,

    THANK YOU VERY MUCH!!! It finally worked 🙂

    Your help is very appreciated!

    #325421 Reply

    support-tony
    Keymaster

    Lofi,

    I’m glad that’s working for you now and thanks for letting us know.

Viewing 12 posts - 1 through 12 (of 12 total)
Reply To: getResource doesn’t work in design mode

This topic is marked as closed to new replies, however your posting capabilities still allow you to do so.

You must be logged in to post in the forum log in