Hi everyone,

I was playing with embedded Tomcat 8.0.33 and I noticed something
unexpected.

If I create my embedded Tomcat like this:

Tomcat tomcat = new Tomcat();
tomcat.setPort(8080);
tomcat.setBaseDir("myBaseDir");

start the server and then try to programmatically deploy a webapp like this:

tomcat.addWebapp(tomcat.getHost(), "/foo", "<absolute path to foo.war>");

I get:

java.io.IOException: Unable to create the directory
[/my-path/myBaseDir/webapps/foo]
    at org.apache.catalina.startup.ExpandWar.expand(ExpandWar.java:115)
~[tomcat-embed-core-8.0.33.jar!/:8.0.33]
    at
org.apache.catalina.startup.ContextConfig.fixDocBase(ContextConfig.java:619)
[tomcat-embed-core-8.0.33.jar!/:8.0.33]
    at
org.apache.catalina.startup.ContextConfig.beforeStart(ContextConfig.java:752)
[tomcat-embed-core-8.0.33.jar!/:8.0.33]
...

If I programmatically create the folder "webapps" in my baseDir after
starting tomcat but before deploying the webapp everything works fine.

So I checked the line of code which throws the exception in the class
org.apache.catalina.startup.ExpandWar:

[line 113] // Create the new document base directory
[line 114] if(!docBase.mkdir() && !docBase.isDirectory()) {
[line 115]     throw new IOException(sm.getString("expandWar.createFailed",
docBase));
[line 116] }

and I guess if the "mkdirs" method was used instead of "mkdir" everything
would work.

The questions are:
- is it done on purpose? (not creating the webapps folder within the
baseDir when needed e.g. when an application is programmatically deployed)
- if yes, what is the reason beyond this technical decision?

Thanks in advance,
Fabrizio

Reply via email to