无法创建 tempDir,java.io.tmpdir 设置为 C:\Windows\
Unable to create tempDir, java.io.tmpdir is set to C:\Windows\
我正在使用 Spring 嵌入式启动 tomcat,一切正常,但突然出现错误:
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
我没有对用户或系统变量进行任何操作。
我的 TEMP user 变量正在 C:/Users/me/AppData/Local/Temp 上查找,我猜 tomcat 必须使用系统一的这个值,实际上是 C:/Windows/Temp
我观察到以下行为
- 突然变了
- 如果 运行 从命令行作为独立的 jar 工作
- 当 运行 来自 IntelliJ (2018.1)
时失败
作为快速解决方法,我在 运行 配置中明确添加了 -Djava.io.tmpdir=$EXISING_DIR_WITH_WRITE_ACCESS
作为 JVM 参数。
如果您使用 IDEA,请在 Run/Debug 配置中的环境变量 window 中检查 "Include parent environment variables"。
就我而言,当我将默认工作区库从 [jre.1.8.0_121] 更改为 [jdk.1.8.0_121] 时出现了问题。将其设置回 jre 似乎已解决问题。
如果你使用eclipse,请在Run/Debug配置的环境变量window中检查"Append to environment variables"。
感谢@max 上面的回答
我正在使用 JAVA EE eclipse - photon
On Windows GetTempPathA 用于定位临时目录。算法:
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.
因此,如果您的应用在未定义 TMP
& TEMP
& USERPROFILE
的情况下启动,您将得到 java.io.tmpdir
== c:\Windows
(https://docs.microsoft.com/en-us/windows/desktop/api/sysinfoapi/nf-sysinfoapi-getwindowsdirectorya).
通常应用程序在 app-run.bat
(通过 -D...=...
)或 app.properties
.
中设置 java.io.tmpdir
我遇到这个问题是因为 Gradle Test
如果 environment
属性没有被传递而是被替换,任务将不会传递环境变量:
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
}
我正在使用 Spring 嵌入式启动 tomcat,一切正常,但突然出现错误:
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
我没有对用户或系统变量进行任何操作。
我的 TEMP user 变量正在 C:/Users/me/AppData/Local/Temp 上查找,我猜 tomcat 必须使用系统一的这个值,实际上是 C:/Windows/Temp
我观察到以下行为
- 突然变了
- 如果 运行 从命令行作为独立的 jar 工作
- 当 运行 来自 IntelliJ (2018.1) 时失败
作为快速解决方法,我在 运行 配置中明确添加了 -Djava.io.tmpdir=$EXISING_DIR_WITH_WRITE_ACCESS
作为 JVM 参数。
如果您使用 IDEA,请在 Run/Debug 配置中的环境变量 window 中检查 "Include parent environment variables"。
就我而言,当我将默认工作区库从 [jre.1.8.0_121] 更改为 [jdk.1.8.0_121] 时出现了问题。将其设置回 jre 似乎已解决问题。
如果你使用eclipse,请在Run/Debug配置的环境变量window中检查"Append to environment variables"。
感谢@max 上面的回答
我正在使用 JAVA EE eclipse - photon
On Windows GetTempPathA 用于定位临时目录。算法:
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.
因此,如果您的应用在未定义 TMP
& TEMP
& USERPROFILE
的情况下启动,您将得到 java.io.tmpdir
== c:\Windows
(https://docs.microsoft.com/en-us/windows/desktop/api/sysinfoapi/nf-sysinfoapi-getwindowsdirectorya).
通常应用程序在 app-run.bat
(通过 -D...=...
)或 app.properties
.
java.io.tmpdir
我遇到这个问题是因为 Gradle Test
如果 environment
属性没有被传递而是被替换,任务将不会传递环境变量:
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
}