【问题标题】:How to create war in specific location using maven tomcat plugin如何使用 maven tomcat 插件在特定位置创建战争
【发布时间】:2018-09-19 07:11:40
【问题描述】:

我使用 maven 的 tomcat 插件将我的 web 应用程序部署到 tomcat 服务器。现在我需要在不同的位置使用相同的war文件(不直接部署到tomcat服务器。)。这样我就可以手动将我的 war 文件复制到另一台机器上并部署它。

我当前的 pom.xml 配置是

      <profiles>
    <profile>
        <id>staging</id>
        <build>
            <pluginManagement>
                <plugins>
                    <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>mytomcat</server>
                            <path>/project1</path>
                                <username>xxxxxxx</username>
                            <password>xxxxxxxx</password>
                        </configuration>
                    </plugin>
                </plugins>
            </pluginManagement>
        </build>
    </profile>

【问题讨论】:

标签: spring-boot maven-plugin maven-tomcat-plugin


【解决方案1】:

您可以使用个人资料。

<profiles>
    <profile>
        <id>otherOutputDir</id>
        <build>
            <directory>yourDirectory</directory>
        </build>
    </profile>
</profiles>

参考

Maven: How to change path to target directory from command line?

Maven: specify the outputDirectory only for packaging a jar?

【讨论】:

    【解决方案2】:

    最简单的方法是将Spring Boot Maven Plugin 添加到项目的 pom.xml(使用 Maven 3.2 或更高版本),如下所示:

            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>2.0.5.RELEASE</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
    

    以及您需要的工件类型,即您的 pom 的 project 标记内的 jarwar,如下所示:

    <packaging>war</packaging>
    

    接下来,无论何时运行 maven 的 package 阶段(例如使用 mvn package 命令),都会在 target 文件夹中生成工件。 Spring 文档here 中提供了更多信息。

    其他生成war/jar神器的方式,请参考这个Baeldung article

    【讨论】:

      猜你喜欢
      • 2015-08-14
      • 2014-01-19
      • 1970-01-01
      • 2012-03-28
      • 2010-11-14
      • 1970-01-01
      • 2012-03-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多