2

This is the weirdest thing ever. I'm working on an app that I run using Tomcat though IntelliJ IDE. Part of this app creates a folder in the configured %CATALINA_TMPDIR%. For some reason no matter where I point %CATALINA_TMPDIR% to java can't create a folder there, but it can create a folder everywhere else.

For example, If CATALINA_TMPDIR=C:\Users\dallend\.IntelliJIdea14\system\tomcat\Unnamed_datasite_7\temp then my app can't create a folder there, but can create it in C:\Temp, a folder I created.

Then if I change to CATALINA_TMPDIR=C:\Temp, the app won't be able to create a directory there but will be able to create one at C:\SomewhereElse.

From debugging through things it appears that java.io.File tries to create the directory but that the WinNTFileSystem.public native boolean createDirectory() method can't successfully create it.

Why might this happen? Could there be something I need to tweak with IntelliJ, or Java, or my OS? Has anyone encountered this before?

EDIT: I've tried running Tomcat stand-alone, and the problem persists.

David
  • 14,569
  • 34
  • 78
  • 107
  • Do you get any errors when you try to create the directory? – logee Jul 16 '15 at 01:04
  • From your question it is unclear whether the app can create a directory _anywhere_. Can it? This sounds like you might have a permission issue. Try running Tomcat in administrator mode. – Tim Biegeleisen Jul 16 '15 at 01:05
  • @TimBiegeleisen, I tried to explain in my question that my app can create folders other places, just not wherever happens to be configured as CATALINA_TMPDIR. For example, If CATALINA_TMPDIR=C:\Temp, then my app won't be able to create folders in C:\Temp but will be able to create folders in C:\SomewhereElse – David Jul 16 '15 at 01:34
  • @user2341963, I don't get any errors. WinNTFileSystem.public native boolean createDirectory() returns false rather than throwing an exception. – David Jul 16 '15 at 01:35
  • @TimBiegeleisen, How do I run tomcat in administrator mode? – David Jul 16 '15 at 01:37
  • Assuming you are launching Tomcat from a command prompt, you need to open a command prompt in admin mode. Right click the command prompt icon and choose run as administrator. Then let Tomcat deploy your WAR as usual. Maybe this will work. – Tim Biegeleisen Jul 16 '15 at 01:39
  • @TimBiegeleisen, it appears that my command prompt runs as Administrator by default. I.e. Every window I open with it is titled "Administrator: Command Prompt" – David Jul 16 '15 at 01:42
  • How are you assiging the `CATALINA_TMPDIR` environment variable? I believe you may have given it a value which appears correct, but which is not a valid formatted path. – Tim Biegeleisen Jul 16 '15 at 01:44
  • @TimBiegeleisen, when running through intelliJ CATALINA_TMPDIR is configured via the tomcat run configuration. When running from the command line, CATALINA_TMPDIR is set via an environmental variable. In both cases it is set to C:\Temp. I'm sure this folder exists since I created it manually. – David Jul 16 '15 at 02:00
  • What does `echo %CATALINA_TMPDIR%` show? – Tim Biegeleisen Jul 16 '15 at 02:05
  • @TimBiegeleisen, It shows C:\Temp. I'm sure that the path is correct and is being passed in correctly since tomcat logs out what value it's using for CATALINA_TMPDIR when it starts up. – David Jul 16 '15 at 02:12

1 Answers1

1

Try to use forward slashes in your directory names. I've pulled out a lot of hair with backslashes actually escaping a path, e.g. C:\temp pointing to C:<tab>emp. I've completely given up on using backslashes even on Windows: Java will translate forward slashes just fine: C:/temp/

Olaf Kock
  • 46,930
  • 8
  • 59
  • 90