Welcome to MacForumz.com!
FAQFAQ      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

java app

 
   Macintosh computer (Home) -> General Discussion RSS
Next:  Is a dual processor machine any faster for MPW?  
Author Message
Francesco1

External


Since: Nov 06, 2003
Posts: 11



(Msg. 1) Posted: Fri Mar 12, 2004 11:27 pm
Post subject: java app
Archived from groups: comp>sys>mac>programmer>misc (more info?)

I wrote a simple java program that uses NSVoiceRecognition Class.
When I run it from XCODE everything works fine and the listening
window opens with the list of words to be listened for...
When I double click on the .app the program runs up to the point where
it is supposed to listen for the list of words but the listener opens
listening for nothing... the list of words is empty...
Any idea why is this happening??

 >> Stay informed about: java app 
Back to top
Login to vote
Sherm Pendley

External


Since: Jul 09, 2004
Posts: 149



(Msg. 2) Posted: Sat Mar 13, 2004 2:46 am
Post subject: Re: java app [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Francesco wrote:

 > I wrote a simple java program that uses NSVoiceRecognition Class.
 > When I run it from XCODE everything works fine and the listening
 > window opens with the list of words to be listened for...
 > When I double click on the .app the program runs up to the point where
 > it is supposed to listen for the list of words but the listener opens
 > listening for nothing... the list of words is empty...
 > Any idea why is this happening??

How are you getting the list, from an absolute path or one that's relative
to the current directory? You should always use full paths, because the
current directory varies - when running within Xcode it's the build
directory, but when run from Finder it's '/'.

If the list is stored somewhere in the application bundle, you can get a
path to it with NSBundle. The +mainBundle method returns the .app bundle,
and there are a number of -pathFor... methods that can be called on that to
find various components within it.

sherm--<!-- ~MESSAGE_AFTER~ -->

 >> Stay informed about: java app 
Back to top
Login to vote
Francesco1

External


Since: Nov 06, 2003
Posts: 11



(Msg. 3) Posted: Sat Mar 13, 2004 7:21 pm
Post subject: Re: java app [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Sherm Pendley <spamtrap DeleteThis @dot-app.org> wrote in message news:<qImdnaOyEpG6D8_dRVn_iw DeleteThis @adelphia.com>...
 > Francesco wrote:
 >
  > > I wrote a simple java program that uses NSVoiceRecognition Class.
  > > When I run it from XCODE everything works fine and the listening
  > > window opens with the list of words to be listened for...
  > > When I double click on the .app the program runs up to the point where
  > > it is supposed to listen for the list of words but the listener opens
  > > listening for nothing... the list of words is empty...
  > > Any idea why is this happening??
 >
 > How are you getting the list, from an absolute path or one that's relative
 > to the current directory? You should always use full paths, because the
 > current directory varies - when running within Xcode it's the build
 > directory, but when run from Finder it's '/'.
 >
 > If the list is stored somewhere in the application bundle, you can get a
 > path to it with NSBundle. The +mainBundle method returns the .app bundle,
 > and there are a number of -pathFor... methods that can be called on that to
 > find various components within it.
 >
 > sherm--


Sherm
first of all thank you for taking the time to answer this question.
You might have hit the right problem. I am using the "." path to get
the path to the file that contains the list of words. The problem is
that I cannot use absolute paths because I don't know where the end
user will end up putting this program (most likely it will be
distributed on a CD-ROM).
The question is now: what is "." when I run the .app file?
Is there a way on a mac to use an absolute path to the cd-rom drive?
Let's say I give a particular name to the CD-ROM, is there a way to
build an absolute path to it that is always going to work, no matter
which computer you stick the cd-rom in?
Sorry if the question sounds silly, but I am a newbie to os x java
programming.
Thanks again for your help!!!

Francesco --<!-- ~MESSAGE_AFTER~ -->
 >> Stay informed about: java app 
Back to top
Login to vote
Eric Albert1

External


Since: Jan 09, 2004
Posts: 408



(Msg. 4) Posted: Sat Mar 13, 2004 9:36 pm
Post subject: Re: java app [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

In article <fe3cbf7c.0403131621.58f1349e DeleteThis @posting.google.com>,
gallarotti DeleteThis @hotmail.com (Francesco) wrote:

 > The question is now: what is "." when I run the .app file?
 > Is there a way on a mac to use an absolute path to the cd-rom drive?
 > Let's say I give a particular name to the CD-ROM, is there a way to
 > build an absolute path to it that is always going to work, no matter
 > which computer you stick the cd-rom in?
 > Sorry if the question sounds silly, but I am a newbie to os x java
 > programming.

By default, the working directory for .app-packaged Java applications on
Mac OS X is inside the .app directory (I think). You can change that in
your app's Info.plist file by setting the WorkingDirectory key to an
$APP_PACKAGE-relative path. See
<http://developer.apple.com/documentation/Java/Reference/Java14JavaDict/K
eysValues/chapter_3_section_1.html> for details.

Hope this helps,
Eric

--
Eric Albert ejalbert DeleteThis @cs.stanford.edu
<a style='text-decoration: underline;' href="http://rescomp.stanford.edu/~ejalbert/" target="_blank">http://rescomp.stanford.edu/~ejalbert/</a><!-- ~MESSAGE_AFTER~ -->
 >> Stay informed about: java app 
Back to top
Login to vote
Sherm Pendley

External


Since: Jul 09, 2004
Posts: 149



(Msg. 5) Posted: Sat Mar 13, 2004 11:29 pm
Post subject: Re: java app [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Francesco wrote:

 > that I cannot use absolute paths because I don't know where the end
 > user will end up putting this program (most likely it will be
 > distributed on a CD-ROM).

Use NSBundle's +mainBundle method, which returns an instance that
corresponds to the .app bundle. Then use one of NSBundle's many -pathFor...
object methods to obtain the full path to the resource you need within that
bundle.

The advantage of using NSBundle methods is that you'll be able to find files
that are within the .app bundle, regardless of where the .app bundle is
located on disk.

 > The question is now: what is "." when I run the .app file?

It's "/" when you run it from Finder or use the "open" command from
Terminal, and the build directory when you run it from PB/Xcode.

 > Is there a way on a mac to use an absolute path to the cd-rom drive?

Assuming it's mounted, and the volume name is "MyCD":

/Volumes/MyCD/

If you're using Cocoa (I believe you mentioned that), you can also register
to receive one or more interesting notifications fired by NSWorkspace:
NSWorkspaceDidMountNotification, NSWorkspaceDidMountNotification, or
NSWorkspaceWillUnmountNotification. Each of these includes the path of the
volume that (will be|was) (mounted|unmounted).

sherm--<!-- ~MESSAGE_AFTER~ -->
 >> Stay informed about: java app 
Back to top
Login to vote
Miro Jurisic

External


Since: May 10, 2004
Posts: 973



(Msg. 6) Posted: Sun Mar 14, 2004 3:56 am
Post subject: Re: java app [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

In article <v-adna09xpMcKM7d4p2dnA.RemoveThis@adelphia.com>,
Sherm Pendley <spamtrap.RemoveThis@dot-app.org> wrote:

 > Assuming it's mounted, and the volume name is "MyCD":
 >
 > /Volumes/MyCD/

No. You can mount multiple volumes with the same name, and their mountpoints do
not all have the same name.

meeroh

--
If this message helped you, consider buying an item
from my wish list: <http://web.meeroh.org/wishlist><!-- ~MESSAGE_AFTER~ -->
 >> Stay informed about: java app 
Back to top
Login to vote
Sherm Pendley

External


Since: Jul 09, 2004
Posts: 149



(Msg. 7) Posted: Sun Mar 14, 2004 1:58 pm
Post subject: Re: java app [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Miro Jurisic wrote:

 > In article <v-adna09xpMcKM7d4p2dnA.RemoveThis@adelphia.com>,
 > Sherm Pendley <spamtrap.RemoveThis@dot-app.org> wrote:
 >
  >> Assuming it's mounted, and the volume name is "MyCD":
  >>
  >> /Volumes/MyCD/
 >
 > No. You can mount multiple volumes with the same name, and their
 > mountpoints do not all have the same name.

Real advice would have been more useful than simply saying "no, you're
wrong."

Anyway, in the event of duplicate volume names, the mount points will look
like this:

/Volumes/MyCD/
/Volumes/MyCD 1/
/Volumes/MyCD 2/
.... etc

It's not all that difficult to prevent the above from happening, or at least
to make it absurdly unlikely to happen. If you give your CDs reasonable,
unique volume names such as "MyCorp. Application version 5.63a", then about
the only way it's going to happen is if the user inserts both your original
CD and a copy of it at the same time. Even in that unlikely event, it
doesn't really matter which one you read from.

sherm--<!-- ~MESSAGE_AFTER~ -->
 >> Stay informed about: java app 
Back to top
Login to vote
Display posts from previous:   
   Macintosh computer (Home) -> General Discussion All times are: Pacific Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]