¿Cómo encontrar el directorio de ejecución base actual en groovy (o java)? [duplicar]
Esta pregunta ya tiene una respuesta aquí:
Tengo un pequeño script que estoy usando un parámetro para pasar en el directorio de ejecución actual, pero me gustaría hacerlo un poco más robusto.
¿Cómo se encuentra el directorio de ejecución base?
23
Author: Scott Bennett-McLeish, 2011-06-27
3 answers
Prueba esto:
System.getProperty("user.dir");
31
Author: rodion,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-06-27 11:40:17
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-06-27 11:40:17
Para referencia:
La respuesta aceptada a la pregunta aquí es lo que estaba buscando.
Como ejemplo, al llamar a c:\scripts\MyScript.groovy
desde c:\users\Scott\
quería saber c:\scripts\
.
Esto se hace a través de esto:
def scriptDir = getClass().protectionDomain.codeSource.location.path
Donde scriptDir se asigna algo así como:
/c:/scripts/MyScript.groovy
14
Author: Scott Bennett-McLeish,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-05-23 12:17:47
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-05-23 12:17:47
Dependiendo del modelo de seguridad, si el System.getProperty(String)
no está permitido, puede usar
String currentDir = new File(".").getAbsolutePath()
12
Author: Aleks G,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-06-27 11:43:48
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-06-27 11:43:48