views:

608

answers:

3

Hi,

does anyone know a way to configure a maven goal to deploy to a tomcat server after a build is run? I know that this is possible using the maven-tomcat-plugin but it looks as though as this only works for Maven 2 whereas I'm using Maven 1.1

I'm currently trying to set up Hudson so this would be part of my continuous intergration phase which I hope will run like this:

  1. Build all necessary components
  2. Build war and deploy to (local) server
  3. Run selenium tests

Any help with this would be much appreciated.

Thanks.

A: 

Honestly I would refactor your project to use Maven 2, there are several guides that can help ease migration pain (google maven 2 migration), and there is even the maven-one-plugin to convert your project.xml or package your Maven 1 plugins for Maven 2.

If you can't do that, you could use the Maven 1 ant plugin to copy the war to tomcat's webapps directory after it has been packaged. Tomcat will detect the new war and should hot-deploy it.

Rich Seller
A: 

I have to admit, I don't know much about the plugin for maven, but I do everything in a simple script that cleans the work directories as well (don't know if the maven plugin cleans the work directories).

CALL mvn clean install
CALL rm C:\apps\tomcat\webapps\Foo.war 
CALL rm -rdf C:\apps\tomcat\webapps\foo
CALL rm -rdf C:\apps\tomcat\work\Catalina
CALL copy C:\webapps\workspace\Foo\target\Foo.war C:\apps\tomcat\webapps\Foo.war /y

(I know, -1 for MS scripting)

The point is you generally want to clean the work directory and the webapps directory and the Maven 1 ant plugin does not do this (as far as I know if, and read from the link provided). Tomcat is "supposed" to recreate the class files in these directories when it explodes the war file, but anybody who has worked with it long enough knows: this isn't always the case.

Therefore, if the plugin does not clean these directories, it's useless as far as I am concerned. Write yourself a cheap little script like the one provided. It takes 2 minutes.

amischiefr
I think this is the best solution for now too. Although that first line should read:CALL maven clean installsince I'm using Maven 1 ;)Thanks a lot!
Gearóid
A: 

I've figured out that best way to do this - its actually pretty easy to write a maven goal to transfer the war. The goal could be written as follows:

<goal name="deployWar" prereqs="buildWar">

 <echo message="+---------------------------------------------------+" />
 <echo message="installing war file to server" />
 <echo message="+---------------------------------------------------+" />

 <j:set var="deploy.dir" value="${server}/webapps" />

 <copy file="${maven.build.dir}/${pom.artifactId}.war"
  todir="${deploy.dir}" overwrite="true" />
</goal>

The server variable can be determined in your project.properties file. Also be sure to specify that a pre-requisite to build the WAR before you try to deploy it. Hope this helps someone!

Gearóid