Using maven-deploy-plugin

And another very interesting topic is the automatic deploy of the assembled package. Let's say we built our own library using Maven. How do we automatically push it to a local, corporate, or central Maven repository?

Maven has a special maven-deploy-plugin plugin for this . Example:


With these settings, you can push the built library to the Maven repository as a valid package. We will not analyze this process in detail, but briefly consider what is happening here:

The file tag specifies a file that will be pushed to the Maven repository as a new library.

The url tag is the path to the Maven repository (local/corporate/…).

The repositoryId tag specifies the identifier of the repository to which the deployment will be made.

The groupId , artifactId , version tags define the standard package identification in the Maven repository. It is by these three parameters that a library can be uniquely identified.

The packaging tag is used to ensure that the result is sent as a single zip file. If you do not specify it, then there will be one jar file, even if you had several jar files.

The pomFile tag is optional and allows you to send another pom.xml to the repository that does not contain hidden or overhead data.

Deploying a web application to Tomcat using Maven

The most popular web server for Java web applications is Apache Tomcat . And of course, with the help of Maven, you can deploy war files directly to a local or even remote Tomcat server.

We will learn how to install and configure Tomcat sometime later, but now we will only touch on the topic of automatic deployment of our web application.

Step one. We need to give Maven access to the Tomcat server. To do this, open the conf/tomcat-users.xml file in the directory where Apache Tomcat is unpacked and add the manager-gui and manager-script roles :

<?xml version='1.0' encoding='utf-8'?>
  <role rolename="manager-gui"/>
  <role rolename="manager-script"/>
  <user username="admin" password="admin" roles="manager-gui,manager-script" />

Step two. Allow Maven access to Tomcat. To do this, open the $MAVEN_HOME/conf/settings.xml file and add the server:

<?xml version="1.0" encoding="UTF-8"?>
<settings ...>

Step three. We add a special plugin for automated deployment of our application to Apache Tomcat. The plugin is called tomcat7-maven-plugin . By the way, it was created not by the Maven developers, but by the Tomcat developers, as you can guess from the name.


In the configuration section, specify:

  • url is the address where Tomcat is running and the path to manager/text
  • server - server id from the settings.xml file
  • path - the address where the deployed application will be available

Deployment management commands:

mvn tomcat7:deploy Deploy the application to Tomcat
mvn tomcat7:undeploy Remove application from Tomcat
mvn tomcat7:redeploy Re-deploy the application

Deploy with Cargo Plugin

Another useful and versatile plugin for deploying web applications is the Cargo Plugin . He knows how to work with different types of web servers. Here is how to deploy with it in Apache Tomcat:

                	<home>Insert absolute path to tomcat 7 installation</home>
                    <home>Insert absolute path to tomcat 7 installation</home>

To install the web application on your local Tomcat, you just need to run the commands:

mvn install
mvn cargo:deploy

If we want to deploy to a remote web server, then we will have to set up access rights to this server. To do this, you just need to register them in pom.xml :


Deploy with IntelliJ IDEA

Intellij IDEA does all the work itself, all you need is an installed Tomcat .

Step one. Create a local Tomcat configuration:

Step two. Then select the local Tomcat:

Step three. Configuring Tomcat:

Step four. Add the path to the Tomcat folder.

Step five. We add our project as an artifact to Tomcat.

To do this, go to the Deployment tab and click the + button on the right .

That's all.

By the way, if you need to deploy to a remote server, just select Remote Tomcat in the second step.