I made a java application and bundled all classes in jar file.When I run the project from eclipse my app is running successfully,but it is not fetching the images from the desired directory.Please let me know how can we present these image files to the end user (like we present .jar file)
Asked
Active
Viewed 145 times
0
-
How are you reading your images? Where are they placed? Do you want to include them inside jar or to place them in somewhere else? – Pshemo Jul 12 '13 at 09:24
-
Can you share the details about the directory. Also share your code for better help – Juned Ahsan Jul 12 '13 at 09:25
-
3Those resources are known as [tag:embedded-resource]s. That being the case, the resource must be accessed by `URL` instead of `File`. See the [info page](http://stackoverflow.com/tags/embedded-resource/info) for the tag, for a way to form an `URL`. – Andrew Thompson Jul 12 '13 at 09:27
-
See [this](http://stackoverflow.com/questions/13796331/jar-embedded-resources-nullpointerexception/13797070#13797070) answer for help. – David Kroukamp Jul 12 '13 at 10:01
3 Answers
0
Try using getResourceAsStream()
resp. getResource()
in your code. That way you will be able to use the same code whether you decide to put your images in a jar or in a directory. A good explanation can be found here.
Concerning the right path where to put your images during Eclipse development, follow this recommendation.
0
It should work this way:
new ImageIcon(this.getClass().getClassLoader().getResource(imagePath))

M.K.
- 256
- 1
- 6