There is an archetype for the Tomcat Maven plugin to show various features with concrete samples.
Use a released version:
mvn archetype:generate \ -DarchetypeGroupId=org.apache.tomcat.maven \ -DarchetypeArtifactId=tomcat-maven-archetype \ -DarchetypeVersion=2.0
Use a SNAPSHOT version:
mvn archetype:generate \ -DarchetypeGroupId=org.apache.tomcat.maven \ -DarchetypeArtifactId=tomcat-maven-archetype \ -DarchetypeVersion=2.0 \ -DarchetypeRepository=https://repository.apache.org/content/repositories/snapshots/
You will have the following output (we will use a project named tomcat-sample)
.... [INFO] Using property: groupId = org.apache.tomcat.maven Define value for property 'artifactId': : tomcat-sample (project will be created in ./tomcat-sample ) ... cd tomcat-sample
Note: it's a complex hello world sample :-)
The goal is to expose a REST service called HelloService and use it in a web application.
@Path( "HelloService" ) public interface HelloService { @Path( "sayHello/{who}" ) @GET @Produces( { MediaType.TEXT_PLAIN } ) String sayHello( @PathParam( "who" ) String who ); }
The Apache Cxf will be used to expose the implementation as a REST service.
Now you have a standard multi module Maven projects layout:
From the top directory, you can use: mvn tomcat6:run or mvn tomcat7:run (depends on tomcat version you want).
Now hit your browser http://localhost:9090 and you will use a very complicated hello world webapp sample
Use mvn clean install. Default browser is firefox but you can use -Pchrome or -Piexplore.
Now you have now an executable jar/war.
Try it:
cd basic-webapp-exec/target/ java -jar basic-webapp-exec-1.0-SNAPSHOT-war-exec.jar -httpPort 9191
And hit your browser to http://localhost:9191.
So you have a tomcat7 running our fabulous application and without installing nothing !