Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Environment variable to control java.io.tmpdir?

People also ask

How is Java IO Tmpdir set?

The default temporary-file directory is specified by the system property java. io. tmpdir. On UNIX systems the default value of this property is typically "/tmp" or "/var/tmp"; on Microsoft Windows systems it is typically "c:\temp".

Where is Java IO Tmpdir in Linux?

tmpdir . The <process id> is the number of the java process for which you want to display the value of the system variable. Id of the java process you can get by using the jps tool, which list all java processes running on your machine. All JDK tools are located in $JAVA_HOME/bin directory.

What is the value of Java IO Tmpdir?

The java. io. tmpdir system property indicates the temporary directory used by the Java Virtual Machine (JVM) to create and store temporary files. The default value is typically "/tmp" , or "/var/tmp" on Unix-like platforms.

What is ${ Java IO Tmpdir in Windows?

getProperty("java. io. tmpdir") to get the default temporary file location. For Windows, the default temporary folder is %USER%\AppData\Local\Temp. For Linux, the default temporary folder is /tmp.


According to the java.io.File Java Docs

The default temporary-file directory is specified by the system property java.io.tmpdir. On UNIX systems the default value of this property is typically "/tmp" or "/var/tmp"; on Microsoft Windows systems it is typically "c:\temp". A different value may be given to this system property when the Java virtual machine is invoked, but programmatic changes to this property are not guaranteed to have any effect upon the the temporary directory used by this method.

To specify the java.io.tmpdir System property, you can invoke the JVM as follows:

java -Djava.io.tmpdir=/path/to/tmpdir

By default this value should come from the TMP environment variable on Windows systems


Hmmm -- since this is handled by the JVM, I delved into the OpenJDK VM source code a little bit, thinking that maybe what's done by OpenJDK mimics what's done by Java 6 and prior. It isn't reassuring that there's a way to do this other than on Windows.

On Windows, OpenJDK's get_temp_directory() function makes a Win32 API call to GetTempPath(); this is how on Windows, Java reflects the value of the TMP environment variable.

On Linux and Solaris, the same get_temp_directory() functions return a static value of /tmp/.

I don't know if the actual JDK6 follows these exact conventions, but by the behavior on each of the listed platforms, it seems like they do.


You could set your _JAVA_OPTIONS environmental variable. For example in bash this would do the trick:

export _JAVA_OPTIONS=-Djava.io.tmpdir=/new/tmp/dir

I put that into my bash login script and it seems to do the trick.


Use

$ java -XshowSettings
Property settings:
    java.home = /home/nisar/javadev/javasuncom/jdk1.7.0_17/jre
    java.io.tmpdir = /tmp