General:

How to add to the classpath all jar-libraries in the specified directory (for example, lib/)?

It's necessary to add the following lines to the section configuration of the described artifact classpath-maven-plugin:

        <configuration>
            ...
            <path>lib/*.jar</path>
            <isMask>true</isMask>
            ...
        </configuration>
The path parameter specifies a search mask for all jar-libraries in the directory lib/ (relative path from the root of your project), and the isMask = true parameter specifies to the plugin classpath-maven-plugin, that the passed parameter path is a mask for file search.

[top]


How to add to the classpath all jar-libraries in the specified directory including subdirectories?

In addition to the parameters described in the previous question, you must add withSubDir = true parameter to the section configuration of the described artifact classpath-maven-plugin:

        <configuration>
            ...
            <path>lib/*.jar</path>
            <isMask>true</isMask>
            <withSubDir>false</withSubDir>
            ...
        </configuration>
In this case, the described plugin will search all jar-libraries (mask *.jar) starting from the directory lib/ and including all its subdirectories (option withSubDir = true).

[top]


How to manage of the jar-libraries adding, if it is already added through dependency (possibly other version)?

In the described plugin it is possible to manage such collisions as a overlap of jar-libraries already connected via dependency with libraries connected via the classpath-maven-plugin. The overlapDependencyMatch parameter in the section configuration is responsible for this:

        <configuration>
            ...
            <overlapDependencyMatch>true</overlapDependencyMatch>
            ...
        </configuration>
If this parameter is set to true, then all the found library for matching those already in the dependency (regardless of the version of matched artifacts) will rewrite the classpath instead of dependency-libraries. If the parameter is set to false (by default), then dependency-libraries will remain in the classpath.

[top]

Additional:

How to save the resulting classpath to the file or project variable without the direct jar-libraries adding?

In the described plugin it is possible to not override the classpath of your project directly, but write the resulting classpath-string to the file or project variable (with subsequent access to it via ${variableName}). For this the assignProjectClasspath parameter is set to false, and adding the following output parameters for writing classpath-string:

        <configuration>
            ...
            <assignProjectClasspath>false</assignProjectClasspath>
            <outputFile>${project.build.directory}/classpath.txt</outputFile>
            <outputProperty>variableName</outputProperty>
            ...
        </configuration>
As an output parameter which classpath-string will be placed may be:
outputFile - file on the disk;
outputProperty - project variable.

[top]


How to enable error output if no one jar-libraries are not found (for a single path)?

Error output with stopping further plugin execution in the absence of found jar-libraries for a single input configuration parameter path is specified in the section configuration with the parameter errorIsEmptyPath = true:

        <configuration>
            ...
            <errorIsEmptyPath>true</errorIsEmptyPath>
            ...
        </configuration>
This applies both to search by mask (isMask = true), and to indicate the specific jar-library in the input parameters of search (or for a single parameter path, or path for each of a set of section paths).

[top]