Tomcat 7 - Maven Plugin?

断了今生、忘了曾经 提交于 2019-11-27 00:39:09
Pascal Thivent

There is t7mp - a Tomcat 7 Maven Plugin - on Google code.

Cargo (and its Cargo Maven2 Plugin) also has support for Tomcat 7 (this was CARGO-790).

Apache Tomcat Maven Plugin 2.0-beta-1 supports Tomcat 7.

It work for me as the following.

My setting.xml

 <server>  
   <id>local_tomcat</id>  
   <username>ray</username>  
   <password>password</password>  
 </server>  

My plugin configuration

 <plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>tomcat-maven-plugin</artifactId>
  <configuration>
     <server>local_tomcat</server>  
     <url>http://localhost:8080/manager/text</url>  
  </configuration>
 </plugin>

My tomcat-users.xml

 <role rolename="manager-gui"/>
    <role rolename="manager-script"/>
  <user password="password" roles="manager-gui, manager-script" username="ray"/>

i use the official Tomcat7 Maven Plugin from Apache as follows:

            <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat7-maven-plugin</artifactId>
                <version>2.0</version>
                <configuration>
                    <path>/${project.artifactId}</path>
                    <port>8080</port>
                </configuration>
            </plugin>

and to run it: mvn tomcat7:run

Dante

Using maven cargo your can coufigure your project that way :

<plugin>
    <groupId>org.codehaus.cargo</groupId>
    <artifactId>cargo-maven2-plugin</artifactId>
    <version>1.0.6</version>
    <configuration>
        <container>
            <containerId>tomcat7x</containerId>
            <type>installed</type>
            <home>${catalina.home}</home>
        </container>
        <configuration>
            <type>existing</type>
            <home>${catalina.home}</home>
        </configuration>
        <deployer>
            <type>installed</type>
            <deployables>
                <deployable>
                    <groupId>${project.groupId}</groupId>
                    <artifactId>${project.artifactId}</artifactId>
                    <type>war</type>
                </deployable>
            </deployables>
        </deployer>
    </configuration>
</plugin>       

don't forget to configure your catalina.home property

The you can deploy it using:

mvn cargo:deploy
tobr

There is the Tomcat Maven Plugin 7 plugin developed by the Apache Tomcat team.

Currently you have to checkout the sources and install it to your local repository. After that you can use it in the plugin section of your pom:

      <plugin>
          <groupId>org.apache.tomcat.maven</groupId>
          <artifactId>tomcat7-maven-plugin</artifactId>
          <version>2.0-SNAPSHOT</version>
        <executions>
          <execution>
            <id>start-tomcat</id>
            <phase>compile</phase>
            <goals>
              <goal>run</goal>
            </goals>
            <configuration>
                  <path>/</path>
                  <serverXml>src/main/tomcatconf/server.xml</serverXml>
                </configuration>
          </execution>
        </executions>
      </plugin>

After I had this error for three days in a row, here's my solution:

The user you are using to connect needs at least the role manager-script. In your /conf/tomcat-users.xml

<role rolename="manager-script"/>
<user username="test" password="test" roles="manager-script"/>

In your pom.xml, include the following plugin

    <plugin>
      <groupId>org.apache.tomcat.maven</groupId>
      <artifactId>tomcat7-maven-plugin</artifactId>
      <version>2.0</version>
      <configuration>
        <url>http://server.url:8080/manager/text</url>
        <path>/YourApp</path>
        <username>test</username>
        <password>test</password>
      </configuration>
    </plugin>

Contrary to what I found in the internet you DON'T need to edit your maven setting.xml. The tomcat7-maven-plugin can be configured directly in the configuration-tag

A word to the url-tag: I tested the suffix

  • /manager
  • /manager/html
  • /manager/text

of which only /manager/text worked

My versions:

  • Tomcat: 7.0.33
  • Maven: 3.0.4
  • tomcat7-maven-plugin: 2.0
  • Java: 1.7.0_07

I'm using tomcat7-maven-plugin for my embedded tomcat instance. Here is how I have configured it. Since my app requires jaas authentication I can also provide that in the setting itself.

<plugin>
    <groupId>org.apache.tomcat.maven</groupId>
    <artifactId>tomcat7-maven-plugin</artifactId>
    <configuration>
    <!-- http port -->
        <port>8080</port>
        <path>/gcs-explorers</path>
        <contextFile>${basedir}/src/main/webapp/META-INF/context.xml</contextFile>
        <addWarDependenciesInClassloader>true</addWarDependenciesInClassloader>
        <systemProperties>
            <java.security.auth.login.config>${basedir}/conf/jaas.config</java.security.auth.login.config>
        </systemProperties>
        <url>http://127.0.0.1:8080/manager/html</url>
        <username>admin</username>
        <password>admin</password>
        <addContextWarDependencies>true</addContextWarDependencies>
        <addWarDependenciesInClassloader>true</addWarDependenciesInClassloader>
        <configurationDir>${basedir}</configurationDir>
    </configuration>
    <dependencies>
        <dependency>
            <groupId>com.google.protobuf</groupId>
            <artifactId>protobuf-java</artifactId>
            <version>2.2.0</version>
            <type>jar</type>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>com.company.package.jaas</groupId>
            <artifactId>gcs-jaas</artifactId>
            <version>0.0.1-SNAPSHOT</version>
            <type>jar</type>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>com.company.gcs</groupId>
            <artifactId>package-file-share</artifactId>
            <version>0.0.1-SNAPSHOT</version>
            <type>war</type>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>com.oracle</groupId>
            <artifactId>ojdbc6</artifactId>
            <version>11.2.0.3</version>
            <scope>runtime</scope>
        </dependency>
    </dependencies>
</plugin>
ferrema

Actually, the standard plugin works for me . I just had to create the role manager-script in tomcat users and change the url parameter to http://localhost:8080/manager/html in order to make it work :

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>tomcat-maven-plugin</artifactId>
    <configuration>
        <url>http://localhost:8080/manager/html</url>
        <server>local</server>
        <path>/${project.artifactId}</path>
        <update>true</update>
    </configuration>
</plugin>
dont care

For Tomcat 7,

Step 1: Modules tab of server add

Document base: <PATH>\Apache-Tomcat-7.0.0\webapps\manager
Path: /manager

Step 2: Update POM to:

<plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>tomcat-maven-plugin</artifactId>
        <configuration>
          <url>http://localhost:8080/manager/text</url>
          <update>true</update>
                <warFile>target/${project.artifactId}-${project.version}.war</warFile>
                <path>/${project.artifactId}</path>
                <username>tomcat_user</username>
                <password>tomcat_password</password>
        </configuration>
</plugin>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!