• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

JAR + Including Files

 
Ranch Hand
Posts: 495
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So I have 16 classes that I can successfully put into a jar. Then, I have two 6 .au files (Sun audio format). I put these 6 files in a folder. When I ran just the jar, it worked. When I moved the folder away (outside the jar), the sound did not work. I used this command:

and then I tf'd it, and all the files showed up. Since the folder is combined with the Jar file (I know this for a fact because it was larger than my class files), it should work. Is there any way that I can put and access that folder that is inside that Jar from one of the class files? For example, I want to be able to call up a sound file from one of the classes while running a Jar.
Currently, I have my "sound player" set up like this...

How do I access the music files inside the Jar?
Thanks,
John Price aka cc11rocks
 
Saloon Keeper
Posts: 13891
314
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Instead of using File, use Class.getResouceAsStream() to get a stream and pass it to your getAudioInputStream() method.
 
john price
Ranch Hand
Posts: 495
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It still isn't working...

I know for sure these both worked when they were not in a Jar, so the methods' coding is right. Of course I was using a file input instead of a ResourceAsStream...
Please HELP! I've spent probably like 5 hours now trying to figure out the sound system in a Jar...
Thanks,
John Price aka cc11rocks
 
Rancher
Posts: 43027
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Assuming that this class is part of a package, you may want to read the javadocs of the Class.getResourceAsStream method.

I see you still think it's a good idea to swallow exceptions silently.
 
john price
Ranch Hand
Posts: 495
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This worked successfully:

I was about ready to give up .
 
The only taste of success some people get is to take a bite out of you. Or this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic