MyEclipse Forums
This thread has been locked & this forum has been archived.
Please post new topics to General Development
View previous topic Printable version Log in to check your private messages View next topic
Author Message
Lofi
Post subject: getResource doesn't work in design mode  PostPosted: Apr 13, 2012 - 05:45 PM



Joined: Sep 09, 2009
Posts: 59

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!
 
 View user's profile Send private message  
Reply with quote Back to top
support-tony
Post subject:   PostPosted: Apr 16, 2012 - 10:03 AM



Joined: Mar 09, 2011
Posts: 916

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.

_________________
Tony
MyEclipse Support
 
 View user's profile Send private message  
Reply with quote Back to top
Lofi
Post subject:   PostPosted: Apr 16, 2012 - 01:36 PM



Joined: Sep 09, 2009
Posts: 59

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:

Code:
*** 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
 
 View user's profile Send private message  
Reply with quote Back to top
support-tony
Post subject:   PostPosted: Apr 17, 2012 - 08:18 AM



Joined: Mar 09, 2011
Posts: 916

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.

_________________
Tony
MyEclipse Support
 
 View user's profile Send private message  
Reply with quote Back to top
Lofi
Post subject:   PostPosted: Apr 18, 2012 - 05:09 AM



Joined: Sep 09, 2009
Posts: 59

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:

Code:

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:

Code:
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:

Code:
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! :)
 
 View user's profile Send private message  
Reply with quote Back to top
support-tony
Post subject:   PostPosted: Apr 18, 2012 - 12:10 PM



Joined: Mar 09, 2011
Posts: 916

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:
Code:
System.out.println("Base class folder: " + MyFrame.class.getClassLoader().getResource("."));

_________________
Tony
MyEclipse Support
 
 View user's profile Send private message  
Reply with quote Back to top
Lofi
Post subject:   PostPosted: Apr 18, 2012 - 07:10 PM



Joined: Sep 09, 2009
Posts: 59

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! :-)
 
 View user's profile Send private message  
Reply with quote Back to top
support-tony
Post subject:   PostPosted: Apr 19, 2012 - 05:13 AM



Joined: Mar 09, 2011
Posts: 916

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:
Code:
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.

_________________
Tony
MyEclipse Support
 
 View user's profile Send private message  
Reply with quote Back to top
Lofi
Post subject:   PostPosted: Apr 19, 2012 - 07:08 AM



Joined: Sep 09, 2009
Posts: 59

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?
 
 View user's profile Send private message  
Reply with quote Back to top
support-tony
Post subject:   PostPosted: Apr 19, 2012 - 10:56 AM



Joined: Mar 09, 2011
Posts: 916

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:
Code:
ClassLoader matisseClassLoader = MyFrame.class.getClassLoader();
System.out.println("Resource: " + matisseClassLoader.getResource("game/bundles/my.properties"));

_________________
Tony
MyEclipse Support
 
 View user's profile Send private message  
Reply with quote Back to top
Lofi
Post subject:   PostPosted: Apr 19, 2012 - 06:48 PM



Joined: Sep 09, 2009
Posts: 59

Hello support-tony,

THANK YOU VERY MUCH!!! It finally worked :-)

Your help is very appreciated!
 
 View user's profile Send private message  
Reply with quote Back to top
support-tony
Post subject:   PostPosted: Apr 20, 2012 - 03:06 AM



Joined: Mar 09, 2011
Posts: 916

Lofi,

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

_________________
Tony
MyEclipse Support
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT - 6 Hours
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2004 The PNphpBB Group
Credits