Netbeans and deployment

R

RG

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
 
M

Mark Space

RG said:
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?
 
N

Nigel Wade

RG said:
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
 
R

RG

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);
.....

--------------------
 
N

Nigel Wade

RG said:
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.
 
R

RG

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!


:)
 
R

RG

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 :)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top