
Additionally, we'll add a configuration section where we tell Maven that we're using a Tomcat container and also an existing installation.īy setting the container type to installed, we tell Maven that we have an instance installed on the machine, and we provide the absolute URL to this installation.īy setting the configuration type to existing, we tell Tomcat that we have an existing setup that we're using, and no further configuration is required. In the plugins section, we'll then add the cargo maven2 plugin. Notice that we explicitly define the packaging as a WAR without this, our build will fail. To enable Maven to recognize Cargo's commands without typing the fully qualified name, we need to add the Cargo Maven plugin to a plugin group in Maven's settings.xml.Īs an immediate child of the root element, we'll add: We'll navigate to the WEB-INF folder of our newly created project, and create a web.xml file with the following content: Since our web application doesn't contain any servlets, our web.xml file will be very basic. Unlike the Tomcat7 Maven plugin, the Cargo Maven plugin requires that this file is present. If we build, deploy, and load this application as is, it'll print Hello World! in the browser. This will create a complete Java web application in the cargo-deploy directory.

Mvn archetype:generate -DgroupId=com.baeldung -DartifactId=cargo-deploy Finally, the path element defines the context path of our deployment. The server element is the name of the server instance that Maven recognizes. The configuration url is the url to which we're sending our deployment, and Tomcat will know what to do with it. Note that we're using the Tomcat 7 plugin because it works for both versions 7 and 8 without any special changes. Let's head over to the pom.xml and add this plugin:

This will create a complete web application in the directory tomcat-war-deployment, which will print hello world! if we deploy it now and access it via the browser.īut before we do that, we need to make one change to enable Maven deployment. DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false We'll run this command on the console to create a new Java web application: mvn archetype:generate -DgroupId=com.baeldung -DartifactId=tomcat-war-deployment

Let's navigate to where we would like to create the application. Now we'll need to create a basic web application from Maven to test the deployment. Once we have found it, we'll add Tomcat: There are two locations where the settings.xml file may be found:
