Maven plugin for Tomcat 9

后端 未结 3 646
日久生厌
日久生厌 2021-02-01 15:56

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

相关标签:
3条回答
  • 2021-02-01 16:11

    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
    
    0 讨论(0)
  • 2021-02-01 16:12

    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>
    
    0 讨论(0)
  • 2021-02-01 16:23

    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
    
    
    0 讨论(0)
提交回复
热议问题