You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Fabrizio Cucci <fa...@gmail.com> on 2016/06/01 14:30:37 UTC

Embedded Tomcat does not automatically create "webapps" folder

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

Re: Embedded Tomcat does not automatically create "webapps" folder

Posted by Fabrizio Cucci <fa...@gmail.com>.
On 1 June 2016 at 15:38, Mark Thomas <ma...@apache.org> wrote:
>
> On 01/06/2016 15:30, Fabrizio Cucci wrote:
> > 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)
>
> Yes.
>
> > - if yes, what is the reason beyond this technical decision?
>
> The user is expected to define a valid directory for a Host's appBase.
>
> Mark
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>

Hi Mark,

thanks a lot for your prompt reply.

What I still find a bit misleading is the fact that, if the user does
not provide a host's appBase, a default value kicks in (i.e. webapps),
but that value is not really useful unless the user manually creates
that folder. So, from a user prospective, the impression I have is
more of a convention-over-configuration not fully implemented.
Personally, I'd rather see Tomcat failing because of a "missing
mandatory configuration: appBase" and/or, at very least, introduce a
condition that checks whether the appBase folder exists on startup and
throw something like "missing mandatory folder: <configured or
default>" if not.

But I have a very limited view of the codebase and my considerations
could be completely wrong.

Thanks,
Fabrizio

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Embedded Tomcat does not automatically create "webapps" folder

Posted by Mark Thomas <ma...@apache.org>.
On 01/06/2016 15:30, Fabrizio Cucci wrote:
> 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)

Yes.

> - if yes, what is the reason beyond this technical decision?

The user is expected to define a valid directory for a Host's appBase.

Mark


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org