Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find current base execution directory in groovy (or java)? [duplicate]

Tags:

java

groovy

I've got a little script I'm using a paramter to pass in the current execution directory, but would like to make it a little more robust.

How does one find out the base execution directory?

like image 266
Scott Bennett-McLeish Avatar asked Jun 27 '11 11:06

Scott Bennett-McLeish


People also ask

How do I find the Java Runtime directory?

In Java, we can use System. getProperty("user. dir") to get the current working directory, the directory from where your program was launched.

What is dir in groovy script?

dir". This is used as a base for the "File" object so if you System.

What is current directory in Java?

The current working directory is c:\JavaProgram. Now let us understand the above program. The current working directory is obtained by using the key user.dir with the method java.lang.System.getProperty().

How do I set the path of a file in groovy?

Since the path changes machine to machine, you need to use a variable / project level property, say BASE_DIRECTORY, set this value according to machine, here "/home/vishalpachupute" and rest of the path maintain the directory structure for the resources being used. Regards, Rao.


2 Answers

Try this:

System.getProperty("user.dir"); 
like image 129
rodion Avatar answered Sep 22 '22 01:09

rodion


Depending on the security model, if the System.getProperty(String) is not allowed, you can use

String currentDir = new File(".").getAbsolutePath() 
like image 38
Aleks G Avatar answered Sep 21 '22 01:09

Aleks G