Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven plugin for Tomcat 9

I didn't find any tomcat-maven-plugin other than tomcat7-maven-plugin. Can I use it with apache-tomcat-9.0.0.M15?

like image 985
Kuldeep Yadav Avatar asked Dec 26 '16 05:12

Kuldeep Yadav


2 Answers

You can use the plugin to deploy to a separately running tomcat 9.

The run goals won't work, but the deploy goals will.

<plugin>
    <groupId>org.apache.tomcat.maven</groupId>
    <artifactId>tomcat7-maven-plugin</artifactId>
    <version>2.2</version>
    <configuration>
        <url>http://localhost:8080/manager/text</url>
        <server>TomcatServer</server>
        <path>/myapp</path>
    </configuration>
</plugin>

Maven goals:

mvn tomcat7:deploy
mvn tomcat7:undeploy
mvn tomcat7:redeploy

Note: Don't forget to add tomcat user in tomcat-users.xml and maven settings.xml

tomcat-user.xml

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

manager-script role enables applications i.e., maven, to deploy jar/war to application server.

Maven file settings.xml

<?xml version="1.0" encoding="UTF-8"?>
<settings ...>
    <servers>
        <server>
            <id>TomcatServer</id>
            <username>admin</username>
            <password>password</password>
        </server>
    </servers>
</settings>
like image 141
rogue lad Avatar answered Oct 20 '22 08:10

rogue lad


As stated in other answer, tomcat7-maven-plugin can still be used to deploy into a running Tomcat 9 with manager app present. However, to run embedded Tomcat 9, try the Cargo plugin:

<plugin>
  <groupId>org.codehaus.cargo</groupId>
  <artifactId>cargo-maven2-plugin</artifactId>
  <version>1.7.6</version>
  <configuration>
    <container>
      <containerId>tomcat9x</containerId>
      <type>embedded</type>
    </container>
  </configuration>
</plugin>

Start it with:

mvn org.codehaus.cargo:cargo-maven2-plugin:run
like image 12
holmis83 Avatar answered Oct 20 '22 08:10

holmis83