43

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

Kuldeep Yadav
  • 1,664
  • 5
  • 23
  • 41

4 Answers4

27

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>
user2807083
  • 2,962
  • 4
  • 29
  • 37
rogue lad
  • 2,413
  • 2
  • 29
  • 32
13

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
holmis83
  • 15,922
  • 5
  • 82
  • 83
  • I failed with your sugguested trial, but then went to the codehaus cargo site to run with parameter `-Dcargo.maven.containerId=tomcat9x` `-Dcargo.maven.containerUrl=http://mirror.netinch.com/pub/apache/tomcat/tomcat-8/v8.5.47/bin/apache-tomcat-8.5.47.zip` and eventually succeeded – Rui Nov 10 '19 at 23:44
  • 1
    Does it not pick the web app automatically as tomcat-7-plugin does? – Kuldeep Yadav Apr 20 '20 at 17:28
  • "tomcat7-maven-plugin" had a "url" and "path" options. I could not find the same or similar functionality in "cargo-maven3-plugin" – Andrey Apr 07 '22 at 16:27
  • cargo-maven2-plugin is deprecated, by the way – Andrey Apr 07 '22 at 16:27
8

I'm finding answer for same question long time. Now I found.

            <plugin>
                <groupId>org.codehaus.cargo</groupId>
                <artifactId>cargo-maven2-plugin</artifactId>
                <version>1.8.3</version>
                <configuration>
                    <container>
                        <containerId>tomcat9x</containerId>
                        <type>embedded</type>
                    </container>
                    <deployables>
                        <deployable>
                            <type>war</type>
                            <location>${project.build.directory}/${project.build.finalName}.war</location>
                            <properties>
                                <context>/</context>
                            </properties>
                        </deployable>
                    </deployables>
                </configuration>
            </plugin>

And run with

mvn package cargo:run

hurelhuyag
  • 1,691
  • 1
  • 15
  • 20
  • how to start it in `pre-integration-test` phase and stop it in `post-integration-test` phase, like it is done [here](https://stackoverflow.com/a/35561792/4412885) ? – mihca Apr 12 '22 at 14:05
  • @mihca I have no experience of that. Did you try creating 2 execution setups. one is pre-integration-test to start. second one is for post-integration-test to stop – hurelhuyag Apr 13 '22 at 02:22
  • I found more documentation on [Cargo website](https://codehaus-cargo.github.io/cargo/Starting+and+stopping+a+container.html) . Note that the documentation uses the newer `cargo-maven3-plugin`. The older Maven2 Plugin was a reason for some of my trouble. – mihca Apr 14 '22 at 08:28
0

I got this to work with the cargo-maven3-plugin

<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven3-plugin</artifactId>
<version>1.10.8</version>
<configuration>
    <container>

        <containerId>tomcat9x</containerId>
        <type>installed</type>

        <systemProperties>
            <property1>value1</property1>
        </systemProperties>

    </container>

    <deployables>
        <deployable>
            <artifactId>MYAPP</artifactId>
            <groupId>com.company</groupId>
            <type>war</type>
            <location>${project.build.directory}/${project.build.finalName}.war</location>
            <pingURL>http://127.0.0.1:8080/APP</pingURL>
        </deployable>
    </deployables>

    <configuration>
        <type>existing</type>
        <home>C://DEVTOOLS//apache-tomcat-9.0.36</home>
    </configuration>

</configuration>

<executions>
    <execution>
        <id>start-server</id>
        <phase>pre-integration-test</phase>
        <goals>
            <goal>start</goal>
        </goals>
    </execution>
</executions>
darraghmurphy
  • 2,095
  • 1
  • 12
  • 5