| | |
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:
Solved Threads: 3
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..
i.e. the class MyToolKit is stored in the package project.helpers and would declare it in its code like this..
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.
Say I have a class that is stored on a hard drive like this..
Java Syntax (Toggle Plain Text)
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..
Java Syntax (Toggle Plain Text)
package project.helpers; public class MyToolkit { // .... Code etc here. }
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.
![]() |
Similar Threads
- project plz who can help me (C++)
- Help me to develop Messenger Project (IT Professionals' Lounge)
- Reading from a text file and using it as a database (Visual Basic 4 / 5 / 6)
- Classes-- stuck in the mire of syntax (C++)
- who can help me in c++ project (C++)
- "Input past end of File" error #62 (Legacy and Other Languages)
- Looking for a new lifestyle? Join our team by the sea...read on (Internet Marketing Job Offers)
- National Accounts Manager NEEDED! (Tech / IT Consultant Job Offers)
Other Threads in the Java Forum
- Previous Thread: Help
- Next Thread: [B]Java Excel connectivity[/B]
| Thread Tools | Search this Thread |
actuate android api applet application applications array arrays automation balls bank binary bluetooth business chat class classes clear client code codesnippet collections component database defaultmethod development dice dragging ebook eclipse error event exception formatingtextintooltipjava fractal froglogic game givemetehcodez graphics gui hql html ide image infinite input integer intersect invokingapacheantprogrammatically j2me java javaprojects jni jpanel julia linux list loop looping map method methods mobile mysql netbeans newbie numbers openjavafx parameter php print problem program programming project recursion repositories scanner screen scrollbar server set size sms sort sorting sql sqlserver state storm string sun superclass swing swt text-file threads time tree windows






