• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Directory Location of Your Currently Running Java Application

 
Ranch Hand
Posts: 286
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
In another thread, someone mentioned that if they were _not_
taking the exam, they would like to place the user preferences
in the same directory as the running Java application.
Besides a brute force search on the hard drive or floppy drive,
I didn't know that there was a System.getProperty(String) call
which would return this information. Is there one; and, if not,
how would you determine in what directory your application is
running?
Thanks,
Javini Javono
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yse the user.dir property gives you the running directory.
Mark
 
Javini Javono
Ranch Hand
Posts: 286
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I think my question must have been ill-formed
and confusing. Sorry.
The docs say:
user.dir is
User's current working directory

So, this would not, I don't believe, tell you the
directory of the placement of the .jar file which
contains the running application, but only the
directory of the user from which the user entered
the command.
If the user is in the directory
/Users/mrbean/tmp/
and issues the command
java -jar [path and filename.jar]
then when the application within this .jar file ran
and asked for System.getProperty("user.dir");
it would return
/Users/mrbean/tmp/ (or something like this)
but not the actual path and filename.jar where
the application is located on disk.
At least, that is how I understand it.
If my understanding is correct, then I still
don't understand how a running application
determines which directory it resides on
on the physical hard drive, or if this
is even possible to know besides a search
of the hard drive.
Thanks,
Javini Javono
 
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Javini,
Take a look at the code Phil posted in this thread - in that he has sample code for locating what directory the jar file is in.
But also note that the instructions for the new assignments are explicit - the properties file must be in the current working directory. Since it is a must requirement you risk automatic failure if you do not follow this.
Regards, Andrew
 
Tongue wrestling. It's not what you think. And here, take this tiny ad. You'll need it.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic