Tobias
Tobias

Reputation: 21

How do I change the Tomcat default working directory?

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?

Upvotes: 1

Views: 10046

Answers (1)

Kenster
Kenster

Reputation: 25390

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.

Upvotes: 2

Related Questions