1

Possible Duplicate:
Get the application's path

I have made a Java Swing Desktop application in Netbeans which can play media files I have put the videos in my workspace resources location and in my java program I am calling those media files using an URL which is something like this:

C:/users/Dell/My Documents/NetBeansProjects/Media/src/resources/MediaFiles/ddd.mpg

This works well when I run in my IDE and also i have made Jar for this it works well on my computer but the problem is when i copy this jar file on my friends system the interface is coming but when I click a button to play a media file it says the file does not exist.

So, please provide me a solution of how to set the default path so that when I run a jar file on other systems it should play the media file location I am passing as in my program.

How to set the path for the location of media files in program?

Update

The videos are in the jar file.

Community
  • 1
  • 1
Zaheer
  • 123
  • 5
  • 14
  • @Andrew Thompson :Yes the videos are in jar file – Zaheer Sep 08 '12 at 09:07
  • This is the URL C:/Users/DELL/Documents/NetBeansProjects/SmartEducation/src/smarteducation/resources/MediaFiles/animation.mpg – Zaheer Sep 08 '12 at 09:19
  • it is location to my video files – Zaheer Sep 08 '12 at 09:22
  • See my answer below, I would advise against packaging these types of resources inside a jar file. Rather you should use the link in m4tx's comment to help you determine the application's working directory and use that as the location for your resources; ship the default resources in the same folder as your application jar. If you prefer a different directory in a production environment then you can easily change the location. –  Sep 08 '12 at 09:24
  • 2
    certainly duplicated in http://stackoverflow.com/q/12329590/203657 - as @JordanWhite already wrote there: if you have trouble to fully understand the answers given here, it doesn't help at all to duplicate the question (the answers will basically be the same). A better strategy is to stick to this question and try harder to understand them .. – kleopatra Sep 08 '12 at 09:46

1 Answers1

2

If the videos are in the jar file, they are effectively an

Note that the strings in the URLs above, are more reminiscent of paths of File instances, as opposed to a file based URL or URI.

Consult the embedded resource info. page for details of using getResource(String) to gain an URL to embedded resources.

Packaging video in a Jar

It is optimal to put resources such as video or sound samples into a separate Jar to classes because that makes it simpler to specify 'no compression' for the media resources. Zip style compression generally does nothing for media types beyond making the 'compressed' resource a few bytes bigger.

Extracting resources from a Jar

If there is any need to extract the resources and have them at a known location (e.g. videos that are played using Desktop.open(File)), see this answer for a strategy to extract them. The 'known location' is a sub-directory of user.home.

Community
  • 1
  • 1
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433