This post shows the way to configure and deploy a JavaWeb Maven project on a remote Tomcat server.
Tomcat Server Configuration
On Tomcat server, tomcat-admin-webapps is required for deploying project remotely (tomcat8-admin-webapps etc.). Once the tomcat-admin-webapps is installed, there should exist host-manager and manager in the tomcat/webapps folder. To get access to the manager website, we need to set up users with specific roles in the tomcat/conf/tomcat-users.xml. Here is an example of setting up a user for deploying projects:
1 2 3 4 5
<tomcat-users...> <rolerolename="manager-gui"/><!-- For manage online on /manager/html --> <rolerolename="manager-script"/><!-- For remote deployment --> <userusername="yourUsername"password="yourPassword"roles="manager-gui,manager-script"/> </tomcat-users>
The plugin tomcat-maven-plugin is used for deploying Java Web project on remote tomcat server. In the configuration label, as server label is used, the server should be configured in the setting.xml (default as ~/.m2/setting.xml) as follows:
The advantage of using server label is to avoid uploading sensitive information (username and password of tomcat-user) as a Git project. Of course, it's also possible to indicate the username and password directly in the pom.xml: