I want to have one JAR and nothing else, I want all external resources to be contained in it. How do I do that?
Asked
Active
Viewed 1,512 times
3
-
How are you building your jar ? – Santosh Aug 20 '12 at 06:42
-
Meaning, are you using command line tool or using some build tool like Ant or Maven ? – Santosh Aug 20 '12 at 06:49
-
i just press run button in the Eclipse IDE :DD – nicks Aug 20 '12 at 06:55
-
Go to command prompt and type `jar -uvf
`
1 Answers
2
What you are trying to do with the media will make it into what is typically called an 'embedded resource'. For that scenario, simply put the WAV files in the Jar and access them by URL. See this info. page for how to form the URL.

Community
- 1
- 1

Andrew Thompson
- 168,117
- 40
- 217
- 433
-
-
A jar is just a zip file with another extension. Depending on the build system you are using you'll do one way or another. But the goal is having a jar with all your .class (code) and all your other files (resources as .wav and so on) – helios Aug 20 '12 at 06:48
-
+1 @Andrew: `getClass().getResourceAsStream(...)` is also handy. I prefer it when I need an InputStream. – helios Aug 20 '12 at 06:49
-
@helios so you're saying that I should put all my resources in `src` folder? – nicks Aug 20 '12 at 06:59
-
1@Nika: well, if you're using Eclipse then yes, it will pack all resources alongside compiled classes. The `Export | Java | Jar` option has a checkbox that says *include generated classes and resources*. Resources means exactly that: non Java files that exists in your src folder. – helios Aug 20 '12 at 07:05
-
2@NikaGamkrelidze : Else you can do that manually, here is one example, [HOW TO MAKE .jar FILE MANUALLY](http://stackoverflow.com/a/9613766/1057230) – nIcE cOw Aug 20 '12 at 07:28