• Post Reply Bookmark Topic Watch Topic
  • New Topic

Netbeans, problems with source files with jar  RSS feed

 
Jose Kreif
Greenhorn
Posts: 22
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I build my jar with netbeans it won't play the sound file. I have output the exception and I see messages like this.



Here is the files from Netbeans panel.


Here are the files when I open the Jar with 7Zip




Everything is there.


Now, If I go to command prompt and do



I get a jar where the sound actually works. Opening it with 7Zip, it looks the same as the one netbeans makes.



---------
I'm close, but no cake.

It seems that the program is looking for the data file outside of it (in the same folder).

\thisFolder\myJar.jar
\thisFolder\data\file.wav


 
Stephan van Hulst
Saloon Keeper
Posts: 7986
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you compared the contents of the manifest of the two jars?
 
Jose Kreif
Greenhorn
Posts: 22
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stephan van Hulst wrote:Have you compared the contents of the manifest of the two jars?


Yes. There isnt any difference, except for ant.


NETBEANS
--------------
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.9.4
Created-By: 1.8.0_65-b17 (Oracle Corporation)
Class-Path:
X-COMMENT: Main-Class will be added automatically by build
Main-Class: TipForm


Command Line
----------------
Manifest-Version: 1.0
Created-By: 1.8.0_65 (Oracle Corporation)
Main-Class: TipForm



Playing around some more, here is what I discovered so far

It seems that the program is looking for the data file outside of it (in the same folder).

\thisFolder\myJar.jar
\thisFolder\data\file.wav
 
Stephan van Hulst
Saloon Keeper
Posts: 7986
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What happens if you delete the Class-Path line from the Netbeans generated manifest?
 
Norm Radder
Rancher
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it won't play the sound file.

How is the code accessing the file?
As a resource that can be in a jar file
or as a file that must be on a disk?

The error message makes it look like the code is trying to read a disk file.


 
Jose Kreif
Greenhorn
Posts: 22
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Norm Radder wrote:
it won't play the sound file.

How is the code accessing the file?
As a resource that can be in a jar file
or as a file that must be on a disk?




When compiled in Command Prompt, it looks for data folder inside the jar.
When compiled with netbeans, it looks for the data folder in the same path as the jar (the outside)
 
Norm Radder
Rancher
Posts: 2240
28
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The File class does not look in jar files.

Can the code that uses the sound data be changed to use a resource instead of a disk file? A resource can be placed in a jar file.
 
Jose Kreif
Greenhorn
Posts: 22
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Norm Radder wrote:The File class does not look in jar files.

Can the code that uses the sound data be changed to use a resource instead of a disk file? A resource can be placed in a jar file.


I'm still learning to use netbeans, so you'll need to explain how I got about doing this.
 
Norm Radder
Rancher
Posts: 2240
28
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, I don't know anything about netbeans.
If the code expects the sound file to be in a jar file, then the methods that access it must treat it as a resource not as a disk file. resources are accessed by the Class class's getrResource methods which return a stream or URL that can be used to read the data from the sound file that is in the jar.
 
Jose Kreif
Greenhorn
Posts: 22
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Norm Radder wrote:Sorry, I don't know anything about netbeans.
If the code expects the sound file to be in a jar file, then the methods that access it must treat it as a resource not as a disk file. resources are accessed by the Class class's getrResource methods which return a stream or URL that can be used to read the data from the sound file that is in the jar.



That explains why the command line version works. The fact is it doesn't.

With command line, I have the jar saved in the project folder, so it's reading from the data file in the relative path.

I will try and use the getrResource, now that I now what you mean.
 
Paul Clapham
Sheriff
Posts: 22828
43
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jose Kreif wrote:


To convert this to code which accesses a resource from the classpath:


 
Norm Radder
Rancher
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There may be a problem with a method that expects a File object and not an InputStream.
 
Paul Clapham
Sheriff
Posts: 22828
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Norm Radder wrote:There may be a problem with a method that expects a File object and not an InputStream.


Yup, that's true. But once you've decided to use a resource and not a file, then the earlier decision to pass a File to that method is (retrospectively) a design error which needs to be fixed.
 
Norm Radder
Rancher
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, but what if the design error was done by Sun or Oracle?

We need the OP to tell us what is reading the sound file.
 
Jose Kreif
Greenhorn
Posts: 22
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Norm Radder wrote:Yes, but what if the design error was done by Sun or Oracle?

We need the OP to tell us what is reading the sound file.



 
Norm Radder
Rancher
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks like you are in luck. Read the API doc for the AudioSystem class's methods. There are other versions of the getAudioInputStream method that will take what is returned by the getResource methods.
 
Jose Kreif
Greenhorn
Posts: 22
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Norm Radder wrote:Looks like you are in luck. Read the API doc for the AudioSystem class's methods. There are other versions of the getAudioInputStream method that will take what is returned by the getResource methods.


Okay.

At Least I'm getting somewhere.

Now I just need to deal with

"java.io.IOException: mark/reset not supported"


That's for pointing out the difference between what I had and getResource()
 
Jose Kreif
Greenhorn
Posts: 22
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Everything is Awesome!

I replaced



With




Then I rewrote my method to be like

 
Paul Clapham
Sheriff
Posts: 22828
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Awesome is right! Congrats on getting it to work!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!