0

In my web application, when I do new File(".").getAbsolutePath(), the path returned is <tomcat_home>/bin. I want to change it to <tomcat_home>/webapps/<app_name>.

The default directory for HTML ./path works fine and is the path I want. But the Java path ./Path is different in the same project.

I have tried to add a parameter like workDir="Path" in the <Host> area of the server.xml file on my Tomcat server, but it doesn't work.

How do I change it?

honk
  • 9,137
  • 11
  • 75
  • 83
Tobias
  • 11
  • 1
  • 2

1 Answers1

1

The general question of how to change the working directory of a java process has been asked before. The simple answer is that the java language and the java virtual machine don't provide a way to change the working directory of the JVM process. You won't be able to change the working directory after tomcat has started.

Tomcat's startup scripts (bin/startup.sh and so on) don't set a working directory. The tomcat process will normally inherit whatever the current directory was for the startup script. See this question. To make tomcat start in a different working directory, you'll have to figure out what is launching tomcat, and change that process to change to the desired directory before it runs startup.sh.

Community
  • 1
  • 1
Kenster
  • 23,465
  • 21
  • 80
  • 106