A new system property?

Thorbjørn Ravn Andersen thunderaxiom at gmail.com
Sat May 3 16:30:53 UTC 2008


Paulo Levi skrev  den 03-05-2008 16:46:
> I always thought that System.getProperty("user.dir") was sufficient to
> locate the directory of the "program", meaning that if i wanted to
> write something to the directory where the jar file is i would just
> need to get it.
>
> Not so, that property gets the location where the java command was
> invoked, and thus is completly useless for that that.
> I'd like to propose two new properties: program.home and program.directory.
>
> I can mangle it right now parsing the classpath like so
>   
It gives you the current directory of the user.

You should not depend on external variables, as it is not used if you 
use executable jars etc.

Try looking at 
MyClass.class.getProtectionDomain().getCodeSource().getLocation() (not 
compiled, just derived from javadoc) to get an URL you can work with.





More information about the core-libs-dev mailing list