I have several comments on

2017-11-07 20:07 GMT+03:00 Tobias Soloschenko
> Hi Maxim,
> same for me I just created a simple setup like this:
>         String baseDir =".";
>         String webappDirLocation = "src/main/webapp/";
>         String webxmlDirLocation = "src/main/webapp/WEB-INF/web.xml";
>         Tomcat tomcat = new Tomcat();
>         tomcat.setPort(8080);

1) Maybe you will want to update the test to use a random port number,
so that several tests could be run in parallel.

Use connector.setPort(0) to enable random port number feature (see
followed by connector.getLocalPort(); after startup  (see


An example of a simple test case and use of getPort():

2) Tomcat tests use address="localhost" on connector.
See TomcatBaseTest.setUp()

Running with localhost avoids opening ports on a public interface.

(When running on Windows its Firewall pops up a dialog and asks
whether to allow network access for this software.
Using localhost avoid this dialog.)

>         tomcat.setBaseDir(baseDir);
>         tomcat.getHost().setAppBase(baseDir);
>         tomcat.getHost().setDeployOnStartup(true);
>         tomcat.getHost().setAutoDeploy(true);
>         tomcat.enableNaming();
>         StandardContext ctx = (StandardContext) tomcat.addWebapp("/project", 
> new File(webappDirLocation).getAbsolutePath());
>         File additionWebInfClasses = new File("target/classes");
>         WebResourceRoot resources = new StandardRoot(ctx);
>         resources.addPreResources(new DirResourceSet(resources, 
> "/WEB-INF/classes",
>                 additionWebInfClasses.getAbsolutePath(), "/"));
>         ctx.setResources(resources);
>         ctx.setDefaultWebXml(new File(webxmlDirLocation).getAbsolutePath());
>         tomcat.start();
>         tomcat.getServer().await();

3) In an automated test both "deployOnStartup" and "autoDeploy" flags
should be set to "false".

Do you want that any random files and directories created in a
temporary directory (baseDir) to be auto-deployed
and exposed as web applications in Tomcat?  I guess that you do not
want that, so set those flags to false.

Tomcat.addWebapp explicitly configures a web application.
Auto-deployment is not needed.

> I just placed in a Servlet into my classpath and applied the mapping in the 
> web.xml - with the dependencies of tomcat-embed-core and tomcat-embed-jasper 
> of version 9.0.1 it is not working and with 8.5.23 it does.
> Here is the log of both.
> [...]

Best regards,
Konstantin Kolinko

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

Reply via email to