【问题标题】:How do I configure the Maven WAR plugin to execute the "inplace" goal by default?如何配置 Maven WAR 插件以默认执行“就地”目标?
【发布时间】:2017-11-16 18:28:57
【问题描述】:

我正在使用 Maven 3.2.3 和 Maven War 2.6 插件。我希望默认执行 Maven WAR 插件的“inlace”目标(无需在命令行上显式指定“war:inlace”)。所以我创建了一个配置文件来包含以下内容

<profile>
    <id>dev</id>
    <activation>
            <property>
                    <name>!flag</name>
            </property>
    </activation>
    <build>
            <plugins>
                    <plugin>
                        <artifactId>maven-clean-plugin</artifactId>
                        <version>2.4.1</version>
                        <configuration>
                            <filesets>
                                <fileset>
                                    <directory>${project.basedir}/src/main/webapp/WEB-INF/classes</directory>
                                </fileset>
                                <fileset>
                                    <directory>${project.basedir}/src/main/webapp/WEB-INF/lib</directory>
                                </fileset>
                            </filesets>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-war-plugin</artifactId>
                        <version>2.6</version>
                        <configuration>
                                <useCache>true</useCache>
                                <workDirectory>/tmp/${project.artifactId}/war/work</workDirectory>
                        </configuration>
                        <goals>
                                <goal>inplace</goal>
                        </goals>
                </plugin>
            </plugins>
    </build>
</profile>

使用“mvn help:active-profiles”,当我在我的 WAR 项目上运行“mvn clean install”时,我已经验证了这个配置文件正在被使用。但是,WAR 没有组装到位。例如,我得到输出

[INFO] Packaging webapp
[INFO] Assembling webapp [myproject] in [/Users/davea/Dropbox/workspace/myproject/target/myproject]
[INFO] Processing war project
[INFO] Copying webapp resources [/Users/davea/Dropbox/workspace/myproject/src/main/webapp]
[INFO] Webapp assembled in [17460 msecs]

我还注意到我的 src/main/resources/WEB-INF 文件夹中没有“类”或“lib”资源。我需要进行哪些不同的配置才能使我的 WAR 就地构建?

【问题讨论】:

标签: maven maven-3 maven-war-plugin in-place


【解决方案1】:

这很可能被归类为How to get Maven to run war:exploded but not war:war 的复制品,但略有不同。而不是exploded,它需要是inplace:

<pluginManagement>
        <plugins>
                <plugin>
                    <!-- don't pack the war  -->
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-war-plugin</artifactId>
                    <configuration>
                        <!-- optional, depends on your setup -->
                        <failOnMissingWebXml>false</failOnMissingWebXml>
                    </configuration>
                    <executions>
                        <execution>
                            <id>default-war</id>
                            <phase>none</phase>
                        </execution>
                        <execution>
                            <id>war-inplace</id>
                            <phase>package</phase>
                            <goals>
                                <goal>inplace</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
         ...
    </plugins>
<pluginManagement>

【讨论】:

    【解决方案2】:

    WAR 插件负责收集 Web 应用程序的所有工件依赖项、类和资源,并将它们打包到 Web 应用程序存档中。

    <plugin>
    
      <groupId>org.apache.maven.plugins</groupId>
    
      <artifactId>maven-war-plugin</artifactId>
    
      <version>3.0.0</version>
    
    </plugin>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-11-26
      • 1970-01-01
      • 1970-01-01
      • 2011-06-01
      • 1970-01-01
      • 2023-03-12
      • 2016-09-20
      • 2014-02-23
      相关资源
      最近更新 更多