Tomcat Maven Plugin

maven-tomcatMaven is a great tool. Sometimes is not the most pain-less tool on earth, but there’s a reason if we use the term “dependency hell”. So, when you’re trying to manage such a thing like “dependencies”, especially considering that almost everybody can put their artifacts on maven central, we can surely state that it’s doing his job.

Maven is also all about plugins. One of the most useful for a web applications developer is the:
Tomcat Maven Plugin

<build>
	<plugins>
		<plugin>
			<groupId>org.apache.tomcat.maven</groupId>
			<artifactId>tomcat7-maven-plugin</artifactId>
			<version>2.2</version>
			<configuration>
				<path>/myapp</path>
				<port>8081</port>
			</configuration>
			<dependencies>
				<dependency>
					<groupId>mysql</groupId>
					<artifactId>mysql-connector-java</artifactId>
					<version>5.1.35</version>
				</dependency>
			</dependencies>
		</plugin>
	</plugins>
</build>

This little xml snippet show some interesting things.

  • you can easily configure the context path and the listen port
  • you can add specific dependencies only for the plugin, useful for the usually “provided” libraries excluded from war package

From the command line all you have to do is:

mvn tomcat7:run

Leave a Reply

Your email address will not be published. Required fields are marked *