Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven - maven-war-plugin change destination directory (other than webapp)

Tags:

java

spring

maven

I'm using springboot but I don't want it to copy my webapp folder during maven-war-plugin task because it contains a lot of files like bower_components folder. I'm using grunt so I'm adding another folder to my war.

[INFO] --- maven-war-plugin:2.6:war (default-war) @ saturne ---
[INFO] Packaging webapp
[INFO] Assembling webapp [saturne] in [D:\Workspaces\MyProject\trunk\target\saturne-1.0.0]
[INFO] Processing war project
...
[INFO] Copying webapp resources [D:\Workspaces\MyProject\trunk\src\main\webapp]

I tried a lot of things like excluding it in <resources> or like

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.6</version>
    <configuration>
        <webResources>
            <resource>
                <directory>src/main/webapp</directory>
                <exclude>**/*</exclude>
            </resource>
        </webResources>
    </configuration>
</plugin>

I can't find a way to exclude it from resource copy.

like image 843
Maelig Avatar asked Jan 07 '16 10:01

Maelig


People also ask

What is the folder name where war file is placed after building it by the Maven tool?

The default directory for the exploded WAR is target/<finalName> . The finalName is usually in the form of <artifactId>-<version> . This default directory can be overridden by specifying the webappDirectory parameter.

Where does maven create the war file?

Using the mvn:war:exploded command, we can generate the exploded WAR as a directory inside the target directory. This is a normal directory, and all the files inside the WAR file are contained inside the exploded WAR directory.

What is packagingExcludes?

packagingExcludes: The comma separated list of tokens to exclude from the WAR before packaging. With packagingExcludes, the tokens are completely excluded from the final war file. With warSourceExcludes, the tokens are just ignored when copying the war directory into the war file.


1 Answers

It's not SpringBoot's fault, maven-war-plugins always copy webapp folder, so we changed it's source by our wanted source.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <configuration>
        <warSourceDirectory>${basedir}/src/main/webapp-dist</warSourceDirectory>
     </configuration>
</plugin>
like image 54
Maelig Avatar answered Nov 11 '22 13:11

Maelig