I have a Maven project that starts a tomcat container for pre-integration-tests (jUnit Tests). Most of my tests require that the web-application under tests is restarted. So I'd like to restart the Tomcat container before each jUnit test is executed.
As for now I use the cargo-maven2-plugin to configure the tomcat container.
So, is it possible to start and stop the container with a java statement?
bootstrap.jar and commons-logging-api-1.1.1 from tomcat\bin to your classpath and the following snippet may help,
I'm using follow method:
But is method have a one problem - I need copy WAR file in 'webapps' directory every time have change source code. I thing what copy my class from classpath in web-inf and copy 'jar' from classpath in web-inf/lib.
Yes it is. But I am afriad, how much time will your tests take. You must fix your tests to not depend on server startup and shutdown. Its fine to run tests inside container, but container should be started once before tests.
Well to answer your question, you can execute the relevant
.sh
or.bat
files from Java using system calls. Something like below,Your use case looks extremely weird (having to restart the container between tests) but let's not discuss this. To answer your question, yes it is possible and this can be done using Cargo's Java API.
To start a Tomcat container and deploy your war, you can do something like this in the
setUp()
method:And stop it in the
tearDown()
method.