Current Class Path  
Author Message
betch23





PostPosted: 2003-10-30 0:23:00 Top

java-programmer, Current Class Path 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
 
NoR. Barranco





PostPosted: 2003-10-30 0:59:00 Top

java-programmer >> Current Class Path maybe this can help you :
System.getProperty("java.class.path")

-- noe

"RB" <email***@***.com> wrote in message
news:email***@***.com...
> 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


 
Knute Johnson





PostPosted: 2003-10-30 1:09:00 Top

java-programmer >> Current Class Path No?R. Barranco wrote:

> maybe this can help you :
> System.getProperty("java.class.path")
>
> -- noe
>
> "RB" <email***@***.com> wrote in message
> news:email***@***.com...
>
>>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

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

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

--

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

 
 
David Postill





PostPosted: 2003-10-30 1:56:00 Top

java-programmer >> Current Class Path -----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

In article <email***@***.com>, on 29 Oct 2003 08:22:48 -0800, email***@***.com (RB)
wrote:

| 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?

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:email***@***.com">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

-----BEGIN PGP SIGNATURE-----
Version: PGP 8.0.3 - not licensed for commercial use: www.pgp.com
Comment: Get key from pgpkeys.mit.edu:11370

iQA/AwUBP5/wUnxp7q1nhFwUEQIO+wCfeD2bCbSQrH9qrDcy+8coP05BKAkAniK1
vbbSAOXsT/MlVllsw2xxdIjx
=BBnJ
-----END PGP SIGNATURE-----