473,395 Members | 1,484 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Jar Path Problem...

I have written a java application , and i am using sounds , images which are placed in Sounds and images packages. I am having trouble about this paths.

filePathSounds=getClass().getResource("/Sounds").toString();

// i get the substring because there is file:/C:/JavaProjec....
// i am removing "file:/ "which is 6 characters and getting the proper path
String pathSounds=filePathSounds.substring(6);

public xPlayer k= new xPlayer(pathSounds+"/Bird/cikcik.mp3");
public xPlayer m= new xPlayer(pathSounds+"/Cat/miaw.mp3");

Above codes is how i manage to use relative path thing.. This is actually working when i compile and run using Netbeans.

The Problem is : When i try to make Jar executable file the paths seems don't work i don't get any of my sounds. Basically how should i place the sounds or images so that i can create proper Jar files..

Thanks in advance.
Dec 30 '09 #1
5 3836
RedSon
5,000 Expert 4TB
If you use relative paths your sounds and resources must exist relative to the executable. Make sure your sounds are in the relative location to where the executable is running.
Jan 5 '10 #2
Go with what RedSon said. Make sure the images and sounds are in the directory that is being compiled to a jar.
Jan 7 '10 #3
pbrockway2
151 Expert 100+
// i am removing "file:/ "which is 6 characters and getting the proper path
How do you know the path is correct? Try printing it. In particular if the class is part of a jar archive the resulting string won't make sense either as a file path or a jar: url.
Jan 7 '10 #4
As i mentioned i used breakpoint to see what string is given by "filePathSounds=getClass().getResource("/Sounds").toString();"
and it gives an "file:/" thing , it is unnecessary. if i don't delete it i got an error that says "java.io.FileNotFoundException: file:\C:\Java_Projects\Ney1\build\classes\Sounds\B irds\cikcik.mp3"

i don't know actually when it is a jar file , what is given to that string that i am removing 6 of its first chars...i can not put breakpoint to see what it gives it to me. what to do ?

...
Thanks again.
Jan 7 '10 #5
pbrockway2
151 Expert 100+
You can see the result of removing the first 6 characters of the string form of the resource url by printing it. As mentioned if the class is part of a jar archive, treating the url in this way won't result in a valid anything: neither file name nor url.

My remarks were intended to be othogonal to that of RedSon. You can place the resources somewhere relative to the executable - but only leaves the problem of trying to figure out what the path of that executable is! Getting the getResource() url and dealing with it as if it were a string is more subtle than you seem to imagine and is only going to be effective sometimes.

Techninjaz suggestion of placing the resources inside the jar archive is better. But note that in this case the resources will not be files (they will be entries inside a jar archive) and therefore will not have file names. If there is a constructor that takes a URL argument, use it. (Or any factory method, or any other way of constructing an xPlayer instance using a url). That way resources within a jar archive will be accessible. Sun's Tutorial chapter on Icons has an example of how to access resources packaged within a jar archive.

If you must have the resources as files then consider passing the location of the resources as an argument when you launch the application.
Jan 7 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Glenn A. Harlan | last post by:
Why am I receiving the below error when calling - Path.GetTempFileName() The directory name is invalid. Description: An unhandled exception occurred during the execution of the current web...
1
by: bob | last post by:
I have created a simple Windows service in VB.Net which installs fine using InstallUtil.exe to install it to, for example "c:\test", or "c:\Windows\YellowBanana", but if I install it to "c:\Program...
5
by: David Webb | last post by:
The problem started when the Working Folder for a project was somehow set to the folder of another project. I set the correct working folder in VSS and deleted the .vbproj files that had been...
12
by: Xah Lee | last post by:
Python Doc Problem Example Quote from: http://docs.python.org/lib/module-os.path.html ---------- split( path) Split the pathname path into a pair, (head, tail) where tail is the last...
13
by: Adam | last post by:
Trying to get an asp.net 2.0 app running and am receiving this error. I see a bunch of people with this error on the net, but no solution: Works fine on my local machine, deployed to a server it...
5
by: Sakharam Phapale | last post by:
Hi All, I am using an API function, which takes file path as an input. When file path contains special characters (@,#,$,%,&,^, etc), API function gives an error as "Unable to open input file"....
10
by: wo_shi_big_stomach | last post by:
Newbie to python writing a script to recurse a directory tree and delete the first line of a file if it contains a given string. I get the same error on a Mac running OS X 10.4.8 and FreeBSD 6.1. ...
34
by: Ben Sizer | last post by:
I've installed several different versions of Python across several different versions of MS Windows, and not a single time was the Python directory or the Scripts subdirectory added to the PATH...
2
by: contractsup | last post by:
Environment: $ uname -a AIX <withheld2 5 000100614C00 $ db2level DB21085I Instance "<withheld>" uses "32" bits and DB2 code release "SQL08024" with level identifier "03050106"....
5
by: =?Utf-8?B?SmVmZiBCZWVt?= | last post by:
Before you respond with "just use GetShortPathName" please read the rest. We have an application that places files on a file server using mapped drives as it's path of choice. The reason for...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.