47

How does Tomcat locate webapps directory? Where is this location set? Is it a relative directory?

Jag
  • 1,840
  • 1
  • 17
  • 25
Suzan Cioc
  • 29,281
  • 63
  • 213
  • 385
  • 1
    The location of the `webapps` directory is relative to the Tomcat installation directory, which is known by Tomcat. Why are you asking? – Bernard Apr 09 '12 at 17:02
  • 8
    My motivation is complex :) Just answer if you know. Your answer means `webapps` is relative to `CATALINA_HOME` or what? – Suzan Cioc Apr 09 '12 at 17:17

4 Answers4

61

It can be changed in the $CATALINA_BASE/conf/server.xml in the <Host /> element.

<Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true">

See the Tomcat documentation, specifically the section in regards to the Host container:

Tomcat 6 Configuration

Tomcat 7 Configuration

Tomcat 8 Configuration

Tomcat 9 Configuration

Tomcat 10 Configuration

The default is webapps relative to the $CATALINA_BASE. An absolute pathname can be used.

enter image description here

jumping_monkey
  • 5,941
  • 2
  • 43
  • 58
clmarquart
  • 4,721
  • 1
  • 27
  • 23
  • 3
    Works on Tomcat 8 too. [Tomcat 8 Configuration](http://tomcat.apache.org/tomcat-8.0-doc/config/host.html) – brunodles Mar 19 '15 at 04:01
15

Find server.xml at $CATALINA_BASE/conf/server.xml

Find appBase attribute in <Host> element

by default it will be something like : <Host name="localhost" appBase="webapps ...>

Change appBase to your required path. There are different way people put it, but I use

/c:/myfolder/newwebapps

Remember, no slash at the end, but at start. Also note it's direction as well.

4

Change appBase in server.xml

If you want to keep both previous webapps and a new one, you can use another Host instance with another port defined in tomcat.

Chand Priyankara
  • 6,739
  • 2
  • 40
  • 63
1

I'm using Tomcat through XAMPP which might have been the cause of this problem. When I changed appBase="C:/Java Project/", for example, I kept getting "This localhost page can't be found" in the browser.

I had to add a folder called ROOT inside the Java Project folder and then it worked. Any files you're working on have to be inside this ROOT folder but you need to leave appBase="C:/Java Project/" as changing it to appBase="C:/Java Project/ROOT" will cause "This localhost page can't be found" to be displayed again.

Maybe needing the ROOT folder is obvious to more experienced Java developers but it wasn't for me so hopefully this helps anyone else encountering the same problem.

lmb
  • 321
  • 2
  • 7