4

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?

nicovank
  • 3,157
  • 1
  • 21
  • 42
  • 1
    I'm guessing the tomcat7-maven-plugin is just being used for the final deploy, as part of a larger war project (war)? To refine the generated war file before it gets sent to Tomcat, you would also need to add some configuration for the maven-war-plugin - along [these](https://maven.apache.org/plugins/maven-war-plugin/examples/adding-filtering-webresources.html) lines. – df778899 Mar 07 '18 at 22:07
  • 1
    Hi I think you are trying to do something what isn't right. I suggest to move your code to some other folder like src/main/js (take a look to frontend-maven-plugin) change war build process to add build directory to war file during war assembly. Some guidance already exists take a look to this https://stackoverflow.com/questions/36590900/how-to-configure-npm-to-use-maven-folder-structure-and-war-deployment – Saulius Next Mar 09 '18 at 07:27

2 Answers2

2

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>
Alexander Petrov
  • 9,204
  • 31
  • 70
1

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

Sheel
  • 847
  • 2
  • 8
  • 20