Nav

Integrating with Maven

There are two methods of integrating with the Tcat console’s REST API from Maven. One uses the Maven Antrun Plug-in, and the other uses the Maven Publishing Plug-in. This page describes how to use each.

Maven Antrun Plug-in Continuous Deployment Integration

This method of integrating your Maven build with Tcat Server’s REST API to achieve continuous deployment of your web applications uses the Maven Antrun Plugin to transfer your webapps into Tcat’s console repository, and then trigger a deployment of the new webapp version.

For a complete and working example of a Maven POM file that you can download and try, download the Tcat Maven antrun plugin example zip file and unpack it. The POM file XML that performs the continuous deployment looks like this:


         
      
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
  <executions>
    <execution>
      <id>deploy-to-tcat-server</id>
      <phase>package</phase>
      <goals>
         <goal>run</goal>
      </goals>
      <configuration>
         <tasks>
            <!-- Properties required for calling the
                 update-tcat-deployment target. -->
            <property name="tcat.console.host" value="localhost"/>
            <property name="tcat.console.port" value="8080"/>
            <property name="tcat.console.user" value="admin"/>
            <property name="tcat.console.pass" value="admin"/>
            <property name="tcat.deployment.id" value="local$2d146fd7-4336-442c-9973-e3239000e475"/>
            <property name="war.dist.dir" value="${project.build.directory}"/>
            <property name="war.base.name" value="${project.artifactId}"/>
            <property name="war.name" value="${war.base.name}.war"/>
            <property name="war.filename" value="${war.base.name}-${version}.war"/>
            <!-- Might want to use svn rev number: -->
            <property name="war.rev.number" value="5"/>
              ...
            <!-- Upload (POST) the war file into the
                 Tcat Server console repository. -->
            <echo>POST http://${tcat.console.host}:${tcat.console.port}/console/api/registry/Applications/${war.name} rev ${war.rev.number}</echo>
            <postMethod url="http://${tcat.console.host}:${tcat.console.port}/console/api/registry/Applications/${war.name}"
               doAuthentication="true">
               ...
            </postMethod>
 
            <!-- Retrieve the webapp's deployment metadata
                 from Tcat's console repository. -->
            <property name="tcat.deployment.file" value="${war.dist.dir}/.deployment.txt"/>
            <delete file="${tcat.deployment.file}" failonerror="false"/>
            <get src="http://${tcat.console.host}:${tcat.console.port}/console/api/deployments/${tcat.deployment.id}"
                 dest="${tcat.deployment.file}"
                 username="${tcat.console.user}"
                 password="${tcat.console.pass}"/>
 
             <!-- Update the deployment metadata with the
                  new revision number. -->
             <replaceregexp file="${tcat.deployment.file}"
                  match="${war.name}/[^&quot;/]+"
                  replace="${war.name}/${war.rev.number}"
                  flags="g" byline="true"/>
 
             <!-- PUT the deployment metadata back to the
                  console, and redeploy the webapp. -->
             <echo>Updating deployment metadata and redeploying ${war.name}.</echo>
             <sardine username="${tcat.console.user}"
                      password="${tcat.console.pass}">
                     <put url="http://${tcat.console.host}:${tcat.console.port}/console/api/deployments/${tcat.deployment.id}"
                                  contentType="application/json">
                              <fileset dir="${war.dist.dir}">
                                   <include name=".deployment.txt"/>
                              </fileset>
                       </put>
              </sardine>
            </tasks>
          </configuration>
       </execution>
   </executions>
   ...
</plugin>

You can edit this XML to configure it to change the behavior, such as building and inserting your own webapp version strings, etc.

Maven Publishing Plug-in

If you create a Maven project, you can use the Galaxy Publishing plug-in for Maven to easily publish your project and/or its resources to a Tcat Server repository. To use the plug-in, you add the necessary Maven repositories to your Maven POM, and then configure the plug-in using the <configuration> tags in your POM. The rest of this page describes these tasks.

After using the plug-in to update your applications, you can schedule a script to listen for these updates and automatically redeploy their packages. For an example, see Automatically Redeploying After an Artifact Update.

Adding the Tcat Server Repository to the POM

The first step is to add your Tcat Server repository (or snapshot repository) to your Maven POM. The Tcat Server repository includes the Apache Incubating repository. You add this to the <pluginRepositories> section so that Maven knows where to get the required files:


         
      
1
2
3
4
5
6
7
8
<pluginRepositories>
    <!-- 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>

Configuring 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:


         
      
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<build>
  <plugins>
     <plugin>
        <groupId>org.mule.galaxy</groupId>
        <artifactId>galaxy-maven-publish-plugin</artifactId>
        <version>2.0.0</version>
        <configuration>
          <url>http://localhost:8080/console/api/registry/Applications</url>
          <username>admin</username>
          <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>
...

Configuring Security Information

If you do not want to include the user name and password in your POM, you can put it in your ~/.m2/settings.xml file. The file looks like this:


         
      
1
2
3
4
5
6
7
8
9
<settings>
  <servers>
    <server>
      <id>myServer</id>
      <username>admin</username>
      <password>admin</password>
    </server>
  </servers>
</settings>

To use this security information, add the following tag to your plug-in configuration, replacing myServer with the same ID you used in the settings.xml file above:


         
      
1
2
3
4
5
<configuration>
  ...
  <serverId>myServer</serverId>
  ...
</configuration>