Netbeans and deployment

Discussion in 'Java' started by RG, Apr 24, 2008.

  1. RG

    RG Guest

    I am asking the question which every java programmer asks during his/
    her initial GUI development. How to deploy the project?

    I need to add some audio and images folders to the deployment. I can
    create executable jar file, but its not showing the images as well as
    the audio when run. On the other hand if I run the project from IDE
    (netbeans 6) it works fine.

    Therefore my question is how to add external folders to the project so
    that the final executable includes them all
     
    RG, Apr 24, 2008
    #1
    1. Advertising

  2. RG

    Mark Space Guest

    RG wrote:

    > I need to add some audio and images folders to the deployment. I can
    > create executable jar file, but its not showing the images as well as
    > the audio when run. On the other hand if I run the project from IDE
    > (netbeans 6) it works fine.


    Well, you need to determine why this is. Surely you recieve some sort
    of error message from your correctly instrumented code when you run the
    executable alone?

    >
    > Therefore my question is how to add external folders to the project so
    > that the final executable includes them all


    I don't. I drag and drop files into the NetBeans project. They show up
    in the jar file. I use getResourceAsStream to access them.

    What are you doing? Can you give us a code example that does not work?
     
    Mark Space, Apr 24, 2008
    #2
    1. Advertising

  3. RG

    Nigel Wade Guest

    RG wrote:

    >
    > I am asking the question which every java programmer asks during his/
    > her initial GUI development. How to deploy the project?
    >
    > I need to add some audio and images folders to the deployment. I can
    > create executable jar file, but its not showing the images as well as
    > the audio when run. On the other hand if I run the project from IDE
    > (netbeans 6) it works fine.
    >
    > Therefore my question is how to add external folders to the project so
    > that the final executable includes them all


    There are two options [that I know of].

    The first is to copy the resources into your project. For example if you have a
    set of images you want to be able to load, create an images directory below the
    src directory of your project. Put the images there.

    The second option, if you don't want to copy the resources into your project, is
    to add an additional source directory to the project. Open the project
    Properties dialog, and in the Sources category choose to add a Source Package
    Folder. Add the folder where your images are stored.

    In both cases the images directory should be copied into the jar. To access
    files in the jar you need to use the getResourceAsStream mechanism
    http://java.sun.com/docs/books/tutorial/uiswing/components/icon.html#getresource

    --
    Nigel Wade
     
    Nigel Wade, Apr 24, 2008
    #3
  4. RG

    RG Guest

    I want to play the audio file. I have copied audio folder as a sub
    folder (parent src), but it is not working! If I copy this outside the
    src then it plays, but final jar file does not play (as I mention
    previously)


    *OK* (but final jar file does not plays)
    PROJECT FOLDER
    --SRC
    --Audio

    But this is not working (in both cases)

    PROJECT FOLDER
    --SRC
    |
    -Audio



    ------- CODE -------------
    Clip clip;
    File F = new File("audio/smouse.wav");
    currentSound = AudioSystem.getAudioInputStream(F);
    .....

    --------------------
     
    RG, Apr 24, 2008
    #4
  5. RG

    Nigel Wade Guest

    RG wrote:

    > I want to play the audio file. I have copied audio folder as a sub
    > folder (parent src), but it is not working! If I copy this outside the
    > src then it plays, but final jar file does not play (as I mention
    > previously)
    >
    >
    > *OK* (but final jar file does not plays)
    > PROJECT FOLDER
    > --SRC
    > --Audio
    >
    > But this is not working (in both cases)
    >
    > PROJECT FOLDER
    > --SRC
    > |
    > -Audio
    >
    >
    >
    > ------- CODE -------------
    > Clip clip;
    > File F = new File("audio/smouse.wav");
    > currentSound = AudioSystem.getAudioInputStream(F);


    That is requesting a file from the local filesystem not the jar.
    Did you lookup getResourceAsStream, it applies to all resources within a jar,
    not just images?

    At least Google before posting. Google "play audio from jar" would answer your
    question.

    --
    Nigel Wade
     
    Nigel Wade, Apr 24, 2008
    #5
  6. RG

    RG Guest

    I post it after google! (ofcourse) :)


    Here is the new code.

    ---------------------------------------------------

    try {
    Clip clip;

    InputStream s = this.getClass().getResourceAsStream("/
    audio/smouse.wav");

    currentSound = AudioSystem.getAudioInputStream(s );
    currentSound.getFormat();
    DataLine.Info dlinfo = new DataLine.Info(Clip.class,
    currentSound.getFormat(), ((int) currentSound.getFrameLength() *
    currentSound.getFormat().getFrameSize()));

    clip = (Clip) AudioSystem.getLine(dlinfo);
    clip.open(currentSound);

    clip.start();
    clip.flush();
    clip = null;
    dlinfo = null;


    } catch (LineUnavailableException ex) {

    Logger.getLogger(AComputerUnit.class.getName()).log(Level.SEVERE,
    null, ex);
    } catch (UnsupportedAudioFileException ex) {

    Logger.getLogger(AComputerUnit.class.getName()).log(Level.SEVERE,
    null, ex);
    } catch (IOException ex) {

    Logger.getLogger(AComputerUnit.class.getName()).log(Level.SEVERE,
    null, ex);
    }
    ---------------------------------------------------

    I also tried this >>

    File F = new File("src/com/audioDemo/resources/audio/smouse.wav");

    currentSound = AudioSystem.getAudioInputStream(F);

    but doesn't work!


    :)
     
    RG, Apr 24, 2008
    #6
  7. RG

    RG Guest

    PROBLEM solved!

    Thanks everyone for active participation!


    try {
    Clip clip;

    InputStream s = this.getClass().getResourceAsStream("/
    audio/smouse.wav");

    currentSound = AudioSystem.getAudioInputStream(s );
    currentSound.getFormat();
    DataLine.Info dlinfo = new DataLine.Info(Clip.class,
    currentSound.getFormat(), ((int) currentSound.getFrameLength() *
    currentSound.getFormat().getFrameSize()));

    clip = (Clip) AudioSystem.getLine(dlinfo);
    clip.open(currentSound);

    clip.start();
    clip.flush();
    clip = null;
    dlinfo = null;

    } catch (LineUnavailableException ex) {

    Logger.getLogger(AComputerUnit.class.getName()).log(Level.SEVERE,
    null, ex);
    } catch (UnsupportedAudioFileException ex) {

    Logger.getLogger(AComputerUnit.class.getName()).log(Level.SEVERE,
    null, ex);
    } catch (IOException ex) {

    Logger.getLogger(AComputerUnit.class.getName()).log(Level.SEVERE,
    null, ex);
    }



    Is working fine now! I made mistake in resource placement! Now I can
    deploy and run :)
     
    RG, Apr 24, 2008
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Benny Ng
    Replies:
    0
    Views:
    4,480
    Benny Ng
    Oct 3, 2005
  2. Pimousse
    Replies:
    2
    Views:
    3,699
    Roedy Green
    Apr 21, 2004
  3. Ilias Lazaridis
    Replies:
    0
    Views:
    938
    Ilias Lazaridis
    Dec 12, 2004
  4. Thomas G. Marshall
    Replies:
    2
    Views:
    856
    Thomas G. Marshall
    Oct 16, 2006
  5. Nasser Abbasi
    Replies:
    2
    Views:
    2,790
    Sabine Dinis Blochberger
    Jan 18, 2008
Loading...

Share This Page