javagroovydirectorytmpantbuilder

Groovy AntBuilder - Specify Java Temp Dir


In my Groovy program, I am using Groovy AntBuilder to call the Ant ReplaceRegExp task.

def antBuilder = new AntBuilder()
antBuilder.replaceregexp(....)

However on Unix, I get the following exception:

Could not create tempfile in /tmp
    at org.apache.tools.ant.util.FileUtils.createTempFile(FileUtils.java:941)
    at org.apache.tools.ant.taskdefs.optional.ReplaceRegExp.doReplace(ReplaceRegExp.java:353)

The UNIX user I use to run the Goovy program does not have permissions for the default java temp directory. When using Ant directly, I can work around this by specifying the java.io.tmpdir for Ant using ANT_OPTS.

export ANT_OPTS="${ANT_OPTS} -Djava.io.tmpdir=/scratch/mydir/tmp"

Qs: With Groovy AntBuilder in Groovy code, how can I specify the java.io.tmpdir for AntBuilder?


Solution

  • Would setting java.io.tmpdir with setProperty or passing java.io.tmpdir via -D switch, e.g. -Djava.io.tmpdir=some_path help?