4

我正在使用tomcat7-maven-plugin,我的 Web 应用程序存储在src/main/webapp. 它是一个 React 应用程序,所以我运行npm run build以在src/main/webapp/build. 我的问题是,每当我打包 webapp 时,都会打包整个webapp文件夹(包括node_modules...),而不仅仅是build文件夹。

这是我的插件配置:

<pluginManagement>
    <plugins>
        <plugin>
            <groupId>org.apache.tomcat.maven</groupId>
            <artifactId>tomcat7-maven-plugin</artifactId>
            <configuration>
                <port>9090</port>
                <!-- I am looking for something of the following form -->
                <webappPath>build</webappPath>
            </configuration>
        </plugin>
    </plugins>
</pluginManagement>

我怎样才能让插件只打包webapp/build目录?或者也许有办法至少node_modules从包中排除,因为所有这些模块仅用于创建我的 webapp 的打包版本?

4

2 回答 2

2

tomcat7-maven-plugin 不负责打包你的war文件。它只负责对tomcat进行deploy undeploy start restart等相关操作。

与WAR文件的打包有关的是maven WAR插件https://maven.apache.org/plugins/maven-war-plugin/usage.html

如果要更改 war 插件使用的默认路径,则需要

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <configuration>
        <warSourceDirectory>your source directory</warSourceDirectory>
    </configuration>
</plugin>
于 2018-03-09T10:48:10.913 回答
1

您可以在构建中包含或排除

    <project>
  ...
  <name>My Resources Plugin Practice Project</name>
  ...
  <build>
    ...
    <resources>
      <resource>
        <directory>src/my-resources</directory>
        <includes>
          <include>**/*.txt</include>
        </includes>
        <excludes>
          <exclude>**/*test*.*</exclude>
        </excludes>
      </resource>
      ...
    </resources>
    ...
  </build>
  ...
</project>

Apache Maven 包含或排除

于 2018-03-12T10:30:25.640 回答