Unable to create tempDir, java.io.tmpdir is set to C:\Windows\
Asked Answered
C

6

18

I'm using Spring Boot with embedded tomcat, everything worked fine and suddenly I got the error :

Caused by: org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to create tempDir. java.io.tmpdir is set to C:\Windows\
    at org.springframework.boot.context.embedded.AbstractEmbeddedServletContainerFactory.createTempDir(AbstractEmbeddedServletContainerFactory.java:183)
    at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:165)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:164)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:134)
    ... 11 common frames omitted
Caused by: java.io.IOException: Access is denied
    at java.io.WinNTFileSystem.createFileExclusively(Native Method)
    at java.io.File.createTempFile(File.java:2024)
    at java.io.File.createTempFile(File.java:2070)
    at org.springframework.boot.context.embedded.AbstractEmbeddedServletContainerFactory.createTempDir(AbstractEmbeddedServletContainerFactory.java:174)
    ... 14 common frames omitted

I didn't do any manipulations with user or system variables.

My TEMP user variable is looking on C:/Users/me/AppData/Local/Temp , and I guess tomcat has to use this value insted of system one, which is actually C:/Windows/Temp

Clobber answered 30/5, 2018 at 13:8 Comment(0)
Z
43

If you use IDEA check "Include parent environment variables" in Environment Variables window in the Run/Debug Configuration.

Zimmermann answered 21/6, 2018 at 8:30 Comment(0)
S
9

On Windows GetTempPathA is used to locate temp directory. Algorithm:

1. The path specified by the TMP environment variable.
2. The path specified by the TEMP environment variable.
3. The path specified by the USERPROFILE environment variable.
4. The Windows directory.

So if your app is started without TMP & TEMP & USERPROFILE defined you'll get java.io.tmpdir == c:\Windows (https://learn.microsoft.com/en-us/windows/desktop/api/sysinfoapi/nf-sysinfoapi-getwindowsdirectorya).

Typically applications set java.io.tmpdir inside app-run.bat (via -D...=...) or app.properties.

I hit this problem because Gradle Test task won't pass environment variables if environment properties aren't passed but replaced:

test {
    environment = ["A": "1", "B": "2"] // won't work, because it replaces envs
}

test {
    environment( ["A": "1", "B": "2"] ) // will work, because it appends to existing envs
}
Strap answered 4/4, 2019 at 18:23 Comment(1)
Ah this explains it. At some point I must have switched my Eclipse launch configuration from "Append environment..." to "Replace environment...", zapping those vars. (I thought my app worked like this in the past, but maybe JDK 8 -> 11 or Windows 7 -> 10 may have changed something?)Pamela
U
4

I observed the following behaviour

  • changed all out of a sudden
  • works if run from commandline as self-contained jar
  • fails when run from IntelliJ (2018.1)

As a quick workaround i explicitly added -Djava.io.tmpdir=$EXISING_DIR_WITH_WRITE_ACCESS as JVM parameter in run configurations.

Upturn answered 20/6, 2018 at 7:39 Comment(1)
yes it solves the problem ,but it's more about workarounds, anyway mark as solved,thanksClobber
C
2

If you use eclipse check "Append to environment variables" in Environment Variables window in the Run/Debug Configuration.

Thanks to @max answer above

I was using JAVA EE eclipse - photon

Clop answered 9/12, 2018 at 7:2 Comment(0)
C
0

In my case the problem occurred when I changed my default workspace library from [jre.1.8.0_121] to [jdk.1.8.0_121]. Setting it back to jre seems to have fixed the problem.

Cadmann answered 28/6, 2018 at 10:8 Comment(0)
A
0

If you are using IntelliJ on Windows, open the IDE in administrator mode i.e

  1. In Windows search, type IntelliJ
  2. Select the option of Run as administrator.

This is another workaround.

Abadan answered 1/3 at 14:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.