Getting the base location of a project

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Aug 2005
Posts: 188
Reputation: bops is an unknown quantity at this point 
Solved Threads: 3
bops bops is offline Offline
Junior Poster

Getting the base location of a project

 
0
  #1
Aug 31st, 2008
It is quite hard to explain what I mean here, but...

Say I have a class that is stored on a hard drive like this..
  1. project/helpers/MyToolkit.class

i.e. the class MyToolKit is stored in the package project.helpers and would declare it in its code like this..
  1. package project.helpers;
  2.  
  3. public class MyToolkit {
  4. // .... Code etc here.
  5. }

Say for instance this is stored on the hard drive in the location "C:\MyJavaProjects\MyNewProject\project\helpers\MyToolkit.class" i.e. the base location of the project would be "C:\MyJavaProjects\MyNewProject", where I would like to store things the program can use such as images or configuration files or whatever else.

What I want to know is, from the code of MyToolkit.class i.e. MyToolkit.java... how to find out the base location of the project. I'm aware this could really be done by jumping back 2 directories, since I know MyToolkit is in the package project.helpers, but this is just hard coding from what I already know. I am looking for a method of doing it so that no matter what package, and how many sub-packages MyToolkit could find itself in, how the base location of the whole project can be retrieved. so in the above example I would like a method inside MyToolkit class that can simply work out where the base location is on the actual hard drive, so that method would return the string "C:\MyJavaProjects\MyNewProject".

In the end I just want to keep my program and resources seperate, and therefore need a way of find my way back to the root.

Its been really hard to try to explain it, sorry if it isn't clear.

EDIT:

When the whole thing is done, I intend to jar the whole program up and what I really need is the full path name of the directory the .jar is stored. Can anyone suggest a way of doing this?

Cheers.
Last edited by bops; Aug 31st, 2008 at 10:34 pm.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,483
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 515
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: Getting the base location of a project

 
0
  #2
Sep 2nd, 2008
Try System.getProperty("user.dir")
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC