Thursday, June 04, 2009

Deploying to tomcat using maven

This is a note to capture the process I am currently using to build and deploy a basic web application to tomcat for development.

  1. Create simple web app using archetype.
    mvn archetype:create ... -DarchetypeArtifactId=maven-archetype-webapp
  2. Add server to ~/.m2/settings.xml
      <servers>
        <server>
          <id>local-tomcat</id>
          <username>username</username>
          <password>password</password>
        </server>
      </servers>
    
  3. Add server to toplevel pom.xml
      <build>
        ...
        <plugins>
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>tomcat-maven-plugin</artifactId>
            <version>1.0-beta-1</version>
            <configuration>
              <server>local-tomcat</server>
            </configuration>
          </plugin>
        </plugins>
      </build>
    
  4. compile, test, deploy, and subsequently redeploy
      $ mvn compile
      $ mvn test
      $ mvn tomcat:deploy
      $ mvn tomcat:redeploy
    

Of course what I would dearly love to know is how you configure a server url in the settings.xml file. The documentation I can find (http://mojo.codehaus.org/tomcat-maven-plugin/configuration.html) describes how to use a custom url, and how to configure authentication information. What it doesn't do is explain how you can do both at the same time, and all my attempts have resulted in XML validation errors when trying to run maven --- if I figure it out I'll update this post.

3 comments:

Unknown said...

Regarding manager url in server.xml - the xml supports (and verified) {server}{configuration}{url} http://localhost:8080/manager {/url}{/configuration}{/server}
as used by http://pyx4me.com/pyx4me-maven-plugins/obex-maven-plugin/

Unfortunately, whilst not creating any errors, the tomcat plugin seems not to look for/use it (and defaults to http://localhost:8080/manager)

Will try and post somewhere at mojo and see if they pick up - but feel free to add 'pressure' to the request :)

Unknown said...

I am very pleased and read on your website. I hope you can also visit my website kata kata cinta , kata kata mutiara , operatorku greetings from Indonesia.

Sneha said...

This can get me out of my tomcat issues. Thanks.

mark email tomcat