Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

images are not displaying in executable jar

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);
like image 966
Vinay Avatar asked Mar 16 '12 03:03

Vinay


People also ask

Why can't I run an executable JAR file?

If you do not have Java installed, and the PATH variable is not set correctly, attempts to run a JAR file on Windows or Ubuntu will result in a 'Java not recognized' error. To run a JAR file, you must install the Java JDK or JRE on your computer.

How do I change a JAR file to an executable icon?

You can create a shortcut for the . jar and then you can change it: Right button >> Properties >> Change Icon.


1 Answers

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"));
like image 140
Jakub Zaverka Avatar answered Sep 28 '22 04:09

Jakub Zaverka