Integrating your Maven Build and Tomcat Deployment Maven Publishing Plugin for Tcat Server MuleSource and the MuleSource logo are trademarks of MuleSource Inc. in the United States and/or other countries. All other product and company names and marks mentioned in this document are the property of their respective owners and are mentioned for identification purposes only. All contents Copyright www.mulesoft.com 2008, MuleSource info@mulesoft.com Inc. 1-877-MULE-OSS
Integrating your Maven Build and Tomcat Deployment Overview Apache Tomcat is the world s most widely used application server, with over 1 million downloads per month and over 70% penetration in the enterprise datacenter. Application developers have embraced Tomcat s lightweight simplicity, viewing it as a powerful application platform with none of the cost or complexity of legacy JEE platforms. Apache Maven, a leading open source build automation and project management tool, has also quickly grown in popularity with developers, due to its powerful build automation and dependency management, along with its open source extensibility. Increased use of open source and third party libraries, development teams are finding Maven easier and efficient to use for their builds. The build artifacts produced are often manually copied over to the application container runtime such as Tomcat. There are multiple solutions to automate this process of deploying build artifacts into container runtime. In this paper, we will show how Tcat Server with the Maven Publishing Plug-in dramatically simplifies and automates the build-deploy process, allowing developers to seamlessly publish application builds from Maven directly into Tcat Server s repository, for easy one-click deployment to groups of Tomcat servers. While there are alternative ways of deploying applications to Tomcat directly from Maven, and you do not need to use Tcat Server, the Tcat Server Maven plug-in makes it easy to integrate application deployment as part of your development activities and provides additional diagnostic capabilities for your deployed applications. What is Tcat Server? MuleSoft's Tcat Server is a fully supported Tomcat server that simplifies Tomcat management and application provisioning tasks for administrators. Tcat Server is built on 100% Tomcat, with no changes to the core Tomcat code. Tcat Server includes an in-built repository that can be used to store and version applications, as well as functionality that allows developers to perform one-click provisioning of applications to groups of Tomcat instances. Tcat Server is free for developers to use in their development environments and can be downloaded from http://www.mulesoft.com/. Integrating your Maven Build and Tomcat Deployment 2
Tcat Server s Maven Publishing Plug-in The Maven Publishing Plug-In from MuleSoft allows developers to push web applications built using Maven directly into the Tcat Server repository so that these applications can be deployed to Tomcat. Developers using the plug-in can simply modify the application project s pom.xml file to point to Tcat Server prior to building the project. Maven will automatically push the build directly into the Tcat Server repository, from which the developer can then deploy the application using Tcat Server. Walking Through the Steps For the purpose of illustration, we will use a pom.xml that is built for a sample web application throughout, but you can follow these steps with your own application. Step 1: Create a sample web application If you do not already have a web application that you want to publish to Tcat Server repository, for testing purposes, you can generate a web application stub using mvn. Below is the command to run. (Change mycompany and app names as you would like them to be). mvn archetype:create -DgroupId=com.mycompany.app -DartifactId=my-webapp -DarchetypeArtifactId=mavenarchetype-webapp This will generate the web application stub, and also will generate pom.xml, which you will be modifying in the next step. Step 2: Modify the POM Modify the location details in the Maven pom.xml file to publish the artifact to Tcat Server. There are three modifications that you need to do: The first step is to add the necessary remote plugin repositories to your Maven POM (alternatively, these can also be added to your Maven settings file usually located at ~/.m2/settings.xml). There are 3 remote plugin repositories required MuleForge, Mule Dependencies, and Apache Abdera. Add these to the <pluginrepositories> section so that Maven knows where to get the required files: Integrating your Maven Build and Tomcat Deployment 3
<pluginrepositories> <pluginrepository> <id>muleforge</id> <url>http://repository.muleforge.org</url> <name>muleforge Repository</name> </pluginrepository > <pluginrepository> <id>mule.dependencies</id> <url>http://dist.codehaus.org/mule/dependencies/maven2/</url> <name>mule Dependencies Repository</name> </pluginrepository > <!-- For the Abdera dependencies --> <pluginrepository> <id>apache-incubating</id> <name>apache Incubating Repository</name> <url>http://people.apache.org/repo/m2-incubating-repository/</url> </pluginrepository> </pluginrepositories> The second step is to configure the plug-in. After adding the Maven repositories to the POM, you configure the plug-in as shown in the following example configuration, which publishes the generated WAR from Maven to your Tcat repository (Change the <url> line below to point to your instance of Tcat Server, with the format http://server:port/console/api/registry/applications) <build> <plugins> <plugin> <groupid>org.mule.galaxy</groupid> <artifactid>galaxy-maven-publish-plugin</artifactid> <version>2.0-m4</version> <configuration> <url>http://localhost:8080/console/api/registry/applications</url> <username>admin</username> Integrating your Maven Build and Tomcat Deployment 4
<password>admin</password> <overwrite>true</overwrite>... <!-- Publish generated WAR --> <includes> <include>target/*-${version}.war</include> </includes> </configuration> <executions> <execution> <id>publish-artifacts</id> <phase>package</phase> <goals> <goal>execute</goal> </goals> </execution> </executions> </plugin> Third step is to configure the security information. If you do not want to include the user name and password in your POM as shown above, you can put it in your ~/.m2/settings.xml file. The file will look like this: <settings> <servers> <server> <id>myserver</id> <username>admin</username> <password>admin</password> </server> </servers> </settings> To use this security information in your POM, remove the username and password tags from the POM and add the following tag to your plug-in configuration, replacing myserver with the same ID you used in thesettings.xml file above: <configuration>... <serverid>myserver</serverid> Integrating your Maven Build and Tomcat Deployment 5
... </configuration> Step 3: Build and Upload the Application Now you are ready to build and upload the application to the Tcat Server Repository. NOTE: Make sure that Tcat Server is started prior to executing the next command. Execute the command: mvn package You should see output that looks similar to the following: [INFO] Created artifact <your app>.war (version x.x) [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------------ At this point the build has been uploaded to the Tcat Server repository. The next steps discuss how to deploy the uploaded application to multiple Tomcat Servers using the Tcat Server console. If you would like to automate this process without logging into Tcat Server console, you can write a simple groovy script in the Tcat Server admin console. For details, please see: http://www.mulesoft.org/display/tcat/scripting+examples. Step 4: Verify the Upload Log into the Tcat Server Console and select the Repository tab. Select Applications, and you should see the application you just uploaded. Integrating your Maven Build and Tomcat Deployment 6
Step 5: Package and Deploy the Application To deploy the application, first add it to an application package that specifies the servers where you want it deployed. On the Deployment tab, click New Package, and then add the application and the servers as shown in the following screen: Click Save and Deploy. The Deployment tab shows that the package has been successfully deployed: Integrating your Maven Build and Tomcat Deployment 7
In Conclusion You should now have uploaded an application and successfully deployed it to at least one server. You can view the ~/webapps directory on your server to verify that the application has been deployed. Using the steps above you can modify any pom.xml file and upload the application to Tcat Server, which then allows you to deploy it to one or more servers. About MuleSoft MuleSoft provides enterprise-class software, support and services for the world's most popular open source application infrastructure products, Mule ESB and Apache Tomcat. With the lightweight and powerful Mule ESB and MuleSoft Tcat Server, MuleSoft is bringing simple yet powerful infrastructure to today's dynamic Web applications. Today, MuleSoft products boast more than 1.5 million downloads and over 2,000 production deployments by leading organizations such as Walmart.com, Nestlé, Honeywell and DHL, as well as 5 of the world s top 10 banks. MuleSoft is headquartered in San Francisco with offices worldwide.. For more information: www.mulesoft.com, or email info@mulesoft.com. Download Tcat Server: http://www.mulesoft.com/download/ MuleSoft and the MuleSoft logo are trademarks of MuleSoft Inc. in the United States and/or other countries. All other product and company names and marks mentioned in this document are the property of their respective owners and are mentioned for identification purposes only. All contents Copyright 2009, MuleSoft Inc. Integrating your Maven Build and Tomcat Deployment 8