简体   繁体   中英

Specifying which directory to package using tomcat7-maven-plugin

I am using tomcat7-maven-plugin , and my web application is stored in src/main/webapp . It is a React app, so I run npm run build to generate a "compiled" version in src/main/webapp/build . My problem is that whenever I package the webapp, the whole webapp folder is packaged (including node_modules ...), instead of just the build folder.

Here is my configuration for the plugin:

<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>

How could I make the plugin only package the webapp/build directory? Or maybe is there a way to at least exclude node_modules from the package, since all these modules are only used to create that packaged version of my webapp?

The tomcat7-maven-plugin is not responsible for packaging your war file. It is only responsible for deploy undeploy start restart and other related operations upon tomcat.

It is the maven WAR plugin that is related to the packaging of the WAR file https://maven.apache.org/plugins/maven-war-plugin/usage.html

If you want to change the default path that the war plugin is using then you need to

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <configuration>
        <warSourceDirectory>your source directory</warSourceDirectory>
    </configuration>
</plugin>

You can able to include or exclude in build

    <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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM