Dragana
Dragana

Reputation: 1

Put image in .jar

How to put image in .jar using Eclipse and how to load image from that .jar ?

Upvotes: 0

Views: 1129

Answers (2)

sandlex
sandlex

Reputation: 43

In example below image file is placed to package com/vocrecaptor/swing/resource and set as icon to system tray icon.

SystemTray tray = SystemTray.getSystemTray();
URL imgURL = ClassLoader.getSystemResource("com/vocrecaptor/swing/resource/tray.gif");
Image image = Toolkit.getDefaultToolkit().getImage(imgURL);
trayIcon = new TrayIcon(image, hint, menu);
trayIcon.setImageAutoSize(true);
tray.add(trayIcon);

In Eclipse a jar file can be created from menu File->Export->Java->Runnable JAR file. There you will need to choose executable class. Ant script is also can be generated for you.

Upvotes: 0

bmargulies
bmargulies

Reputation: 100196

Put the image file into your source hierarchy and eclipse will include it in your jar. Call Class.getResourceAsStream to access it from classpath.

Upvotes: 1

Related Questions