Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8408665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:41:45+00:00 2026-06-09T23:41:45+00:00

I have two classes ( Play and editor ). editor uses Play . Play

  • 0

I have two classes (Play and editor). editor uses Play. Play uses some external files. I imported them into Eclipse in order to address them straight (as you can see on the first screenshot).
enter image description here
I want JAR to be able to contain these files withing and be able to work with (import) them. Is that possible? What options should I choose while exporting project to JAR?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T23:41:46+00:00Added an answer on June 9, 2026 at 11:41 pm

    If you want to use the .wav files from within a jar then instead of doing String path = System.getProperty("user.dir"); and then loading the wav files from there, try doing something like :

    InputStream stream = Play.class.getResourceAsStream("/result.wav");
    

    From here, it seems that AudioSystem does have an overloaded getAudioInputStream which accepts an InputStream instead of a File object (as in your code). So you could have something like :

    public class Play{
        public AudioInputStream find(String s) throws UnsupportedAudioFileException, IOException{
            // Probably some try catch over the next statement to log the error if `result.wav` is not found.
            InputStream stream = Play.class.getResourceAsStream("/result.wav");
            return AudioSystem.getAudioInputStream(stream); 
        }
    }
    

    For the above to work all your *.wav files must be copied to a source folder so that they are present on the classpath. To do that you could move *.wav into sint/src to start with (and then into a proper wav folder later on if needed). That would put them in the root of the classpath / and allow them to be referred to like so : /result.wav , /x_SECOND.wav etc.

    Working Code

    Here is a bit of working code to test out AudioInputStream from here :

    public class A {    
        @Test
        public void testAudioInputStream() throws UnsupportedAudioFileException, IOException {
            InputStream stream = A.class.getResourceAsStream("/result.wav");
            System.out.println(stream != null);
            AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(stream);
            System.out.println(audioInputStream != null);
        }    
    }
    

    The above code worked fine for me and I got two true in the console.

    GIT Hub Repo with Test project

    You should be able to import the project in this zip and see the code working.

    Do you need a ‘Fat Jar’ ?

    A bit off-topic, but if you need to build a fat jar that includes all the jars needed by your project to run and is a single executable then try using http://fjep.sourceforge.net/ plugin to build a fat jar.

    You can export a java project containing jars using the File -> Export -> Other -> One Jar Exporter. The jar that’s thus built is an executable jar and needs nothing else to run.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using play-1.2.3. I have two classes some kind of these: LabelItem: @Entity @Table(name=T_LABEL_ITEM)
I have two classes defined in different h files and each class has some
I have two classes, Item and SoldItem . SoldItem inherits from Item adding some
I have two classes Order and Items I want a method like this class
I have two classes, a server and some clients. The server class make a
I have two classes: class Order(models.Model): ... date = models.DateTimeField(blank=True, verbose_name=u'Date add',default=datetime.now) price =
I have two classes (MVC view model) which inherits from one abstract base class.
I have two classes A and B generated by cxf-codegen-plugin from my WSDL. A
I have two classes Foo and Bar . The tables in the database look
I have two classes Foo and Bar that Bar extends Foo as below: class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.