First of all, I will recommend the easiest approach which is packaging the libraries inside of your application (no server.xml <library>
config needed this way). If you are using the maven-war-plugin
, then any non-provided
dependencies will automatically end up in WEB-INF/lib/
of your application. However, if you have more than 1 application in your Liberty server that need the same libraries, this may not be a good solution.
On to your original question, you can use the maven-dependency-plugin
to copy any maven artifact into a particular location during the build. When using this plugin to set up a <library>
, be sure to bind the copy step to the prepare-package
phase.
Here is an example of adding JUnit to ${server.config.dir}/myLib/
during a Maven build:
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<id>copy</id>
<phase>prepare-package</phase>
<goals>
<goal>copy</goal>
</goals>
</execution>
</executions>
<configuration>
<artifactItems>
<artifactItem>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<type>jar</type>
<overWrite>false</overWrite>
<outputDirectory>${project.build.directory}/liberty/wlp/usr/servers/myServer/myLib</outputDirectory>
<destFileName>junit.jar</destFileName>
</artifactItem>
</artifactItems>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
</configuration>
</plugin>
</plugins>
</build>
[...]
</project>