maven-war-plugin copies only subdirectories (including files). Not just files

73 Views Asked by At

I am using the maven-war-plugin (version 3.3.2) in order to copy a jar file from target/lib/v1 into the WEB-INF/lib of the WAR file.

The jar file is located under: target/lib/v1/myJar.jar

The pom.xml looks like this:

        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>3.3.2</version>
        <configuration>
          <webResources>
            <resource>
              <directory>${project.build.directory}/lib/v1</directory>
              <targetPath>WEB-INF/lib</targetPath>
            </resource>
          </webResources>
        </configuration>
      </plugin>

Unfortunately this doesn't work as the jar is not copied under WEB-INF/lib.

I have the feeling that the maven-war-plugin is looking for a folder to copy.

I modified my pom.xml as shown below (I removed the v1):

        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>3.3.2</version>
        <configuration>
          <webResources>
            <resource>
              <directory>${project.build.directory}/lib</directory>
              <targetPath>WEB-INF/lib</targetPath>
            </resource>
          </webResources>
        </configuration>
      </plugin>

and the jar was copied, but with the subfolder v1.

So, the WAR was like this:

    └── WEB-INF
          └─── lib
                └── v1
                     └── myJar.jar

But this one doesn't help, as the jar has to be directly under lib.

Any help would be really appreciated.

1

There are 1 best solutions below

1
Amine Hayani On
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.3.2</version>
<configuration>
    <webResources>
        <resource>
            <directory>${project.build.directory}/lib/v1</directory>
            <targetPath>WEB-INF/lib</targetPath>
            <includes>
                <include>myJar.jar</include>
            </includes>
        </resource>
    </webResources>
</configuration>

With this configuration, only the myJar.jar file will be copied to WEB-INF/lib without the v1 subfolder. The resulting WAR file structure will be as follows:

└── WEB-INF
      └─── lib
            └── myJar.jar

you can specify the specific files you want to include, and any subdirectories will be ignored. This way, you can achieve the desired flattened directory structure in the WAR file.