I have a runnable jar (swing GUI) that uses a lot of resources (Videos, images, texts) and I don't know exactly what is the best way to access these rsc. Now I'm putting all my ressouces in C:\
directory, but when I'm changing the machine I have to transfer all ressources manually to the appropriate directory.
Asked
Active
Viewed 88 times
1

Adil
- 4,503
- 10
- 46
- 63
-
3put them inside jar or to web – Nikolay Kuznetsov Dec 17 '12 at 14:12
-
1Hopefully this [**answer**](http://stackoverflow.com/a/9866659/1057230), might be of some help. But if you doing manually, then this [post](http://stackoverflow.com/a/11372350/1057230), might be able to put some more light on the topic. – nIcE cOw Dec 17 '12 at 14:35
1 Answers
4
The usual approach is to package the resource files in the JAR, typically in or under the same "directory" as the package of the class in question
- com
- example
- MyClass.class
- resources
- icon.png
and then in MyClass
you can use this.getClass().getResource("resources/icon.png")
to access a resource as a java.net.URL
or getResourceAsStream
to access it as an InputStream
.

Ian Roberts
- 120,891
- 16
- 170
- 183