【问题标题】:Specifying which directory to package using tomcat7-maven-plugin使用 tomcat7-maven-plugin 指定要打包的目录
【发布时间】:2018-02-28 05:27:05
【问题描述】:

我正在使用tomcat7-maven-plugin,我的网络应用程序存储在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 的打包版本?

【问题讨论】:

  • 我猜 tomcat7-maven-plugin 只是用于最终部署,作为更大战争项目 (war) 的一部分?要在将生成的 war 文件发送到 Tomcat 之前对其进行优化,您还需要为 maven-war-plugin 添加一些配置 - 沿 these 行。
  • 您好,我认为您正在尝试做一些不正确的事情。我建议将您的代码移动到其他文件夹,例如 src/main/js(查看 frontend-maven-plugin)更改 war 构建过程以在 war 组装期间将构建目录添加到 war 文件。一些指导已经存在,看看这个stackoverflow.com/questions/36590900/…

标签: java maven tomcat7-maven-plugin


【解决方案1】:

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

是maven WAR插件与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>

【讨论】:

    【解决方案2】:

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

        <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 Include or Exclude

    【讨论】:

      猜你喜欢
      • 2014-01-11
      • 1970-01-01
      • 2015-08-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-20
      • 2013-06-29
      • 1970-01-01
      • 2014-08-07
      相关资源
      最近更新 更多