samsri
samsri

Reputation: 1104

providing default tone for alarm application

the structre of the project

I am coding an alarm app in Java in Netbeans. I want to provide default tone with the alarm. I created a folder named rsrc and saved the tone in that folder. I included this code to get the tone

URL turl = this.getClass().getResource("rsrc/bb.mp3");
String s1=turl.getFile();

While this worked in Netbeans it didn't worked in the jar file that netbeans created in the dist folder. Can someone please help me how to get it work with jar file or a way to distribute my application with the default tone include

Upvotes: 0

Views: 161

Answers (2)

Sachin
Sachin

Reputation: 3554

Try this one:

URL turl = this.getClass().getResource("./alarm/rsrc/bb.mp3");
 String s1=new File(turl.getFile()).getAbsolutePath();

Upvotes: 1

stark
stark

Reputation: 13189

Paths are relative to your current directory. When you run the program, this won't work. You need to have or find an absolute install directory and prefix your path with that.

Upvotes: 1

Related Questions