Tomcat Maven 外掛程式有一個原型,可透過具體範例展示各種功能。
使用已發布的版本
mvn archetype:generate \ -DarchetypeGroupId=org.apache.tomcat.maven \ -DarchetypeArtifactId=tomcat-maven-archetype \ -DarchetypeVersion=2.2
使用 SNAPSHOT 版本
mvn archetype:generate \ -DarchetypeGroupId=org.apache.tomcat.maven \ -DarchetypeArtifactId=tomcat-maven-archetype \ -DarchetypeVersion=2.2 \ -DarchetypeRepository=https://repository.apache.org/content/repositories/snapshots/
您將會看到以下輸出(我們將使用一個名為 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
注意:這是一個複雜的 hello world 範例 :-)
目標是公開稱為 HelloService 的 REST 服務,並在 Web 應用程式中使用它。
@Path( "HelloService" ) public interface HelloService { @Path( "sayHello/{who}" ) @GET @Produces( { MediaType.TEXT_PLAIN } ) String sayHello( @PathParam( "who" ) String who ); }
Apache Cxf 將用於公開實作作為 REST 服務。
現在您有一個標準的多模組 Maven 專案配置