The need here is to start a container and to deploy an application from a build script before to run tests depending on the deployed application. This is a typical need for integration tests, end-to-end / functional tests, ui tests.
The problem is that we can't just "fire and forget" the launch of a container and run the test task/goal. We need to wait for the application to be deployed before to run the tests and this takes some time. To be sure we can run tests when things are ready, the build has to start the container and deploy the application in a blocking way.
This is exactly what Cargo is about. Cargo is a Java API to start/stop your container and deploy your application. It provides the logic described above and can be used from Java, Ant or Maven.
If you are using Maven, the build life cycle already includes something for you with the "integration-test" phase. This phase is typically used for... integration tests and is wrapped by the "pre-integration-test" and "post-integration-test" phases. This is where you would plug Cargo start/stop goals. If you are using Ant, you can use cargo's ant task.
Another option based on the maven is described in the Mavan Jetty Plugin Configuration Guide. The idea is exactly the same as above except that you use the jetty plugin instead of cargo to start jetty during the "pre-integration-test" and stop it during the "post-integration-test".