Reputation: 347
i have created executable jar file of my project built in eclipse. but when i execute that file then it does not display icon on system tray that i have added in project. i am using following simple code.
Image image = Toolkit.getDefaultToolkit().getImage("src/resources/ChatIcon1.jpeg");
PopupMenu Popup = new PopupMenu();
MenuItem exit = new MenuItem("Exit");
Popup.add(exit);
final TrayIcon trayIcon = new TrayIcon(image,"OfficeCommunicator",Popup);
trayIcon.setImageAutoSize(true);
Upvotes: 5
Views: 2850
Reputation: 8874
To load resources from within .jar files please use getClass().getResource(). That will return a URL with correct path.
Image img = ImageIO.read(getClass().getResource("path to image"));
Upvotes: 5