I'm new to VScode and tomcat-for-java plugin, I want to run my application with the plugin, but I got a permission denied error when starting up. When starting up, the code will create a temp file and a FileOutputStream, the code snippet which throws exception looks like this, please note that the code is in third party jar file so I can't change it.
File myFile = new File("a.txt");
out = new FileOutputStream(myFile);
I tried using the original tomcat to start up the application with command line ./startup.sh
under tomcat/bin directory, I see the myFile's absolute path is path/to/tomcat/bin
, and when using the VScode tomcat plugin, the myFile's absolute path is /a.txt
which definitely no permission to write to.
I searched a lot about this issue and awared that when creating a relative path file in tomcat, the path will be the user.dir
(system properties) + filename
, and the user.dir
will be determined by the path to start up the tomcat, which is path/to/tomcat/bin
since the startup.sh
is under this directory.
So I tried to add env parameters to VM by passing user.dir
to customize JVM options
in VScode, the file path was changed successfully, but still got permission denied
exception. I even tried to change the file path to the same path with the original tomcat, but still no luck.
So I wonder what's the user.dir
system property when running a war package by right click on the war package then select run on tomcat server
? How can I solve this problem?