Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2005

Tip: Looking for answers? Try searching our database.

Current Class Path

Thread view: 
RB - 29 Oct 2003 17:22 GMT
We are trying to get the current class path of our Java program which
is installed to c:\program files\my program\.  In case the path
changes, we need to get the new path.  Everytime we use the
java.lang.System.getProperty("user.dir"), we get the jdk directory
path opposed to our program path.

Could anyone tell me how to get the class path and not the jdk path?

Thanks in advance
No? R. Barranco - 29 Oct 2003 17:59 GMT
maybe this can help you :
System.getProperty("java.class.path")

-- noe

> We are trying to get the current class path of our Java program which
> is installed to c:\program files\my program\.  In case the path
[quoted text clipped - 5 lines]
>
> Thanks in advance
Knute Johnson - 29 Oct 2003 18:08 GMT
Noé R. Barranco wrote:

> maybe this can help you :
> System.getProperty("java.class.path")
[quoted text clipped - 10 lines]
>>
>>Thanks in advance

new File(".").getCanonicalPath(); or for most applications

new File(".").getAbsolutePath(); will work.

Signature

Knute Johnson
email s/nospam/knute/
Molon labe...

David Postill - 29 Oct 2003 18:56 GMT
| We are trying to get the current class path of our Java program which
| is installed to c:\program files\my program\.  In case the path
[quoted text clipped - 3 lines]
|
| Could anyone tell me how to get the class path and not the jdk path?

Hmm. Not sure exactly what you are trying to do from your description.

Are you trying to get the current working directory?

Try this code and see if it works for you.

 /**
  * Returns a string consisting of the current working directory.
  *
  * @since JToolkit 0.2
  */

 public static String getCWD()
   {
   // [idea courtesy of <a href="mailto:travis@nrg.org.invalid">Travis Thornhill</a>]

   File file;
   int index;
   String pathSeparator;
   String cwd = null;

   file = new File( "." );
   pathSeparator = File.separator;
   index = file.getAbsolutePath().lastIndexOf( pathSeparator );

   try
     {
     cwd = file.getAbsolutePath().substring( 0, index );
     }
   catch ( StringIndexOutOfBoundsException e )
     {
     System.err.println( "Caught Exception: " + e.getMessage() + "\n" );
     }

   return cwd;
   }

Regards,

<davidp />

- --
David Postill
Alexandre Gontijo - 29 Mar 2005 14:34 GMT
I'm needing the same thing here, but none of this solutions worked.
They return other paths, instead of the current class one.
Any other ideas??


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.