• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Finding the path that my Application is running in
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Finding the path that my Application is running in


  • Subject: Re: Finding the path that my Application is running in
  • From: Evan Coyne Maloney <email@hidden>
  • Date: Mon, 4 Feb 2002 12:35:13 -0500

Since you're using Java, there's a little trick for determining the current working directory. Instantiate a File object with a path of ".". Then, call getAbsolutePath() on the File object, and you should be able to tell where the current working directory is. Using Runtime.exec() may result in a different working directory, so you might want to explicitly specify the paths in the command line.

You can experiment with something like this:

String fileToCompile = // whatever this happens to be
File myDir = new File(".");
System.exec("javac " + myDir.getAbsolutePath() + File.separator
+ fileToCompile + " -d " + myDir.getAbsolutePath());

And you can then adjust your System.exec() similarly for "java <compiledClassFile>"

Hope this helps,
Evan

On Monday, February 4, 2002, at 08:35 AM, Andrew Pinski wrote:

Because the current directory when you launch the App from the Finder is "/".
Thanks,
Andrew Pinski
On Monday, February 4, 2002, at 08:18 , Jake MacMullin wrote:

Hi,

I've been writing a simple text editor in Java using the Cocoa API's as a way of learning Cocoa. Among other things this editor allows me to compile and run java files that I'm editing. However, I do this by calling Java's Runtime.exec() method (similar to Cocoa's NSTask), and passing it the command "javac filename.java -d ." (compile the file called filename and put the resulting class file in the current directory)
, followed by "java classname" (run the resulting class file in the current directory).

This works really well when I build the application in Project Builder and run it from my project/build directory. The application puts any created .class files in the same directory that it is in, and when I call run they launch ok.

However, as soon as I move my built application (say to the Applications Directory), something goes wrong. Instead of placing the .class files in the same directory as the Application, my app puts them at the root level of my hard drive. I can't think why this might be happening. As a solution I was wondering if anyone knows of an easy way to find out (at runtime) where my application is running?

Evan Coyne Maloney____________________________________________________
The six-legged fire-breathing dog email@hidden


  • Follow-Ups:
    • Re: Finding the path that my Application is running in
      • From: Markus Hitter <email@hidden>
References: 
 >Re: Finding the path that my Application is running in (From: Andrew Pinski <email@hidden>)

  • Prev by Date: Re: _iVar prefixes (was Re: Draggable buttons)
  • Next by Date: Re: Modification dates and AFP
  • Previous by thread: Re: Finding the path that my Application is running in
  • Next by thread: Re: Finding the path that my Application is running in
  • Index(es):
    • Date
    • Thread