Picking up idea variables programmatically

Hi,

I'm writing some tests and I'd like to be able to programmatically pick up the project root directory from my code.

I know there are idea specific variables such as "MODULE_DIR", but is there any way I can get the project root from my code?

Many thanks

Richard

2 comments
Comment actions Permalink

The only way would be to set the "working directory" text field in the run/debug configuration to the desired directory (or one that is relative to the desired directory) and then use the "user.dir" standard Java System property to access it. Or, of course, just set the property yourself as a VM option.

//Java 7+
Path path = Paths.get(System.getProperty("user.dir"));
//Pre Java 7
File file = new File(System.getProperty("user.dir"));

0
Comment actions Permalink

Thanks

Yeah I went with the user.dir approach.  I wasn't too keen on the custom -D arg in case someone forgot to set it

Many thanks

Richard

0

Please sign in to leave a comment.