samedi 21 février 2015

Getting resources works from NetBeans Execution Context but not working when jar is executed from comand line

I have a code where i create Java Actions and try to associate Icons with them. One snapshot of code is



FileOpenCommand fileOpen = new FileOpenCommand(this);
fileOpen.putValue("ImageOnly", false);
fileOpen.putValue(Action.NAME, "Open");

fileOpen.putValue(Action.SMALL_ICON, new ImageIcon(getClass().getResource("../resources/File-Open-icon24x24.png")));

fileOpen.putValue(Action.SHORT_DESCRIPTION, "Opens the existing file.");
fileOpen.putValue("Group", "File");
fileOpen.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK));

this.commands.put("FileOpen", fileOpen);


The accent is on the line where I try to set the Action.SMALL_ICON property to the action. This works when executed in NetBeans environment either in debug or release mode. But when I've tried to execute jar file from the command line, it fails with exception.


Any idea? Anything to do with classpath? Resources folder is put as the package inside the main package.


Thanks in Advance!


Aucun commentaire:

Enregistrer un commentaire