簡體   English   中英

如何使用maven插件tomcat7:運行多個上下文(WAR)?

[英]How to use maven plugin tomcat7:run with multiple contexts (WARs)?

我一直在使用mvn tomcat7-maven-plugin:run -am -pl :foo成功地在Tomcat中一次只運行一個項目, 如此處所示 現在我想在同一個端口但不同的上下文下運行多個模塊。 例如,我想:

/    => foo.war
/bar => bar.war

這是我一直在使用的示例pom.xml代碼段:

<project><!-- ... -->
    <build><!-- ... -->
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.tomcat.maven</groupId>
                    <artifactId>tomcat7-maven-plugin</artifactId>
                    <version>2.0-SNAPSHOT</version>
                    <configuration>
                        <path>/</path>
                        <port>8080</port>
                        <addContextWarDependencies>true</addContextWarDependencies>
                        <addWarDependenciesInClassloader>true</addWarDependenciesInClassloader>
                        <warSourceDirectory>${project.build.directory}/${project.build.finalName}/</warSourceDirectory>
                    </configuration>
                    <dependencies>
                        <dependency>
                            <groupId>${project.groupId}</groupId>
                            <artifactId>bar</artifactId>
                            <version>${project.version}</version>
                            <type>war</type>
                            <scope>tomcat</scope>
                        </dependency>
                    </dependencies>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
    <pluginRepositories>
        <pluginRepository>
            <id>apache.snapshots</id>
            <name>Apache Snapshots</name>
            <url>http://repository.apache.org/content/groups/snapshots-group/</url>
            <releases>
                <enabled>false</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </pluginRepository>
     </pluginRepositories>
</project>

這可能與tomcat7-maven-plugin:run插件有關嗎? 我很難找到正確的語法來讓它發揮得很好。 當我運行maven命令來運行它時,它只運行它在項目層次結構中找到的第一個命令。 如果我用<fork>true</fork>運行它們,或者顯然是從不同的終端運行它們,那么我得到“java.net.BindException:Address in in use:8080”。

正如已經建議的那樣,使用插件配置的<webapps>部分,但為每個webapp添加額外的參數<asWebapp>true</asWebapp> ,即:

<webapps> 
  <webapp> 
    <groupId>com.company</groupId> 
    <artifactId>mywebapp</artifactId> 
    <version>1.0</version> 
    <type>war</type>    
    <asWebapp>true</asWebapp> 
  </webapp> 
  <webapp> 
    <groupId>com.company</groupId> 
    <artifactId>mywebapp2</artifactId> 
    <version>2.0</version> 
    <type>war</type>    
    <asWebapp>true</asWebapp> 
  </webapp>
</webapps> 

默認情況下,這些額外的Web應用程序使用${artifactId}上下文路徑進行部署。

看起來沒有這個參數,當你運行像mvn tomcat7:run (在穩定版本2.0上試過)之類的東西時,會無聲地丟棄額外的webapps。 相關的Jira問題告訴它是為了“向后兼容性”而完成的。

使用類似的東西

  <configuration>
    <webapps> 
      <webapp> 
        <groupId>com.company</groupId> 
        <artifactId>mywebapp</artifactId> 
        <version>1.0</version> 
        <type>war</type>    
      </webapp> 
    </webapps> 
  </configuration>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM