1

I want when run mvn verify

to include all files from /lib/ folder to war archive in folder 'web-inf/lib`

So here my pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.myhost</groupId>
    <artifactId>sailero</artifactId>
    <name>myapp</name>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>


  <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>1.2.3</version>
        </dependency>
        <dependency>
            <groupId>com.auth0</groupId>
            <artifactId>java-jwt</artifactId>
            <version>3.7.0</version>
        </dependency>
<dependency>
            <groupId>com.host</groupId>
            <artifactId>some-lib</artifactId>
            <scope>system</scope>
            <version>0.0.1</version>
            <systemPath>${project.basedir}/lib/some-lib-0.0.1.jar</systemPath>
</dependency>


<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.2.2</version>
                <configuration>
                    <configuration>
                        <packagingIncludes>lib/*.jar</packagingIncludes>
                    </configuration>
                </configuration>
</plugin>

in console:

mvn verify

But in war NOT INCLUDE some-lib-0.0.1.jar

in war in \target\myapp-1.0-SNAPSHOT.war\WEB-INF\lib\ -> not exist "some-lib-0.0.1.jar", but all other dependencies included.

Alexei
  • 14,350
  • 37
  • 121
  • 240

4 Answers4

2

Maven war plugin automatically copies all the project dependencies into WEB-INF/lib. So if your war needs a dependency just put the relevant GAV into the dependency section of this module.

Example: In your pom, you have a dependency on:

    <dependency>
        <groupId>com.auth0</groupId>
        <artifactId>java-jwt</artifactId>
        <version>3.7.0</version>
    </dependency>

So it will be automatically included appear in WEB-INF/lib of your WAR.

Now it doesn't work like this with dependencies in scope system and this is a root cause of the issue here. Long story short, this question has been already asked/answered in SO.

Bottom line, I suggest getting rid of system dependency and placing it at least in the local repo or ideally in some proxy like Nexus or Artifactory. But of course, you're welcome to test other approaches suggested in the provided link.

Mark Bramnik
  • 39,963
  • 4
  • 57
  • 97
1

This fix problem:

<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.2.2</version>
                <configuration>
                    <webResources>
                        <resource>
                            <directory>lib</directory>
                            <targetPath>WEB-INF/lib</targetPath>
                        </resource>
                    </webResources>
                </configuration>
            </plugin>
Alexei
  • 14,350
  • 37
  • 121
  • 240
1

Here correct approach:

first install "some-lib-0.0.1.jar" in local maven repo:

mvn install:install-file -Dfile=myproject\lib\some-lib-0.0.1 -DgroupId=com.host -DartifactId=some-lib -Dversion=0.0.1 -Dpackaging=jar

and second in pom.xml

   <dependency>
                   <groupId>com.host</groupId>
                   <artifactId>some-lib</artifactId>
                   <version>0.0.1</version>
               </dependency>
Alexei
  • 14,350
  • 37
  • 121
  • 240
0

Also I found another approach:

Create a “lib” folder under your project like this: “\src\main\webapp\WEB-INF\lib” Copy needed “jars” etc that you want included inside your WAR bundle folder. Invoke your maven build as you normally do. I use “mvn install”, which creates builds the war file

Alexei
  • 14,350
  • 37
  • 121
  • 240