Native Libraries distribution
FlatLaf uses native libraries to provide functionality that is not possible with
pure Java. The native libraries are included in flatlaf.jar
. To load and
execute them, it is necessary to extract them to a temporary directory and load
them from there.
This works fine in most cases, but may cause problems on system with enabled execution restrictions. E.g. execution allowed only from installation directory. For this case it is possible to distribute the FlatLaf native libraries with your application.
Since FlatLaf 3.1, following file layouts are supported:
flatlaf-3.1.jar
flatlaf-3.1-linux-x86_64.so
flatlaf-3.1-windows-x86_64.dll
flatlaf-3.1-windows-x86.dll
lib/flatlaf-3.1.jar
bin/flatlaf-3.1-linux-x86_64.so
bin/flatlaf-3.1-windows-x86_64.dll
bin/flatlaf-3.1-windows-x86.dll
FlatLaf finds the native libraries automatically (no extraction to temporary
directory necessary). If the JAR is in a lib
directory then the native
libraries can be placed into a bin
directory.
If you repackaged FlatLaf into a fat/uber application JAR, then naming is different:
myapp-1.0.jar
myapp-1.0-flatlaf-linux-x86_64.so
myapp-1.0-flatlaf-windows-x86_64.dll
myapp-1.0-flatlaf-windows-x86.dll
lib/myapp-1.0.jar
bin/myapp-1.0-flatlaf-linux-x86_64.so
bin/myapp-1.0-flatlaf-windows-x86_64.dll
bin/myapp-1.0-flatlaf-windows-x86.dll
Maven Central
To make it easier to bundle FlatLaf native libraries with your application, they
are uploaded to Maven Central into the com.formdev:flatlaf
artifact. E.g.
https://repo1.maven.org/maven2/com/formdev/flatlaf/3.1/
flatlaf-3.1.jar
flatlaf-3.1-sources.jar
flatlaf-3.1-javadoc.jar
flatlaf-3.1-linux-x86_64.so
flatlaf-3.1-windows-x86_64.dll
flatlaf-3.1-windows-x86.dll
Gradle
To bundle FlatLaf native libraries using Gradle, you can use the Application Plugin and specify all FlatLaf native libraries as dependencies (e.g. in Kotlin DSL):
plugins { application } dependencies { val flatlafVersion = "3.1" implementation( "com.formdev:flatlaf:${flatlafVersion}" ) implementation( "com.formdev:flatlaf:${flatlafVersion}:linux-x86_64@so" ) implementation( "com.formdev:flatlaf:${flatlafVersion}:windows-x86_64@dll" ) // 32-bit (not needed if you bundle a 64-bit JRE with your application) implementation( "com.formdev:flatlaf:${flatlafVersion}:windows-x86@dll" ) }
When running Gradle tasks installDist
, distZip
or distTar
, the native
libraries are copied to the same directory as the FlatLaf JAR.
Maven
To bundle FlatLaf native libraries using Maven, you need to specify all FlatLaf
native libraries as dependencies in pom.xml
:
<project ...> ... <properties> <flatlafVersion>3.1</flatlafVersion> </properties> <dependencies> <dependency> <groupId>com.formdev</groupId> <artifactId>flatlaf</artifactId> <version>${flatlafVersion}</version> </dependency> <dependency> <groupId>com.formdev</groupId> <artifactId>flatlaf</artifactId> <version>${flatlafVersion}</version> <classifier>linux-x86_64</classifier> <type>so</type> </dependency> <dependency> <groupId>com.formdev</groupId> <artifactId>flatlaf</artifactId> <version>${flatlafVersion}</version> <classifier>windows-x86_64</classifier> <type>dll</type> </dependency> <!-- 32-bit (not needed if you bundle a 64-bit JRE with your application) --> <dependency> <groupId>com.formdev</groupId> <artifactId>flatlaf</artifactId> <version>${flatlafVersion}</version> <classifier>windows-x86</classifier> <type>dll</type> </dependency> </dependencies> </project>
To assemble application distributable you can use the Maven Assembly Plugin. E.g.:
<project ...> ... <build> <plugins> <plugin> <artifactId>maven-assembly-plugin</artifactId> <executions> <execution> <phase>package</phase> <goals> <goal>single</goal> </goals> <configuration> <appendAssemblyId>false</appendAssemblyId> <descriptors> <descriptor>src/main/assembly/zip.xml</descriptor> </descriptors> </configuration> </execution> </executions> </plugin> </plugins> </build> </project>
In the assembly descriptor file src/main/assembly/zip.xml
, you need to
specified that all dependencies (including native libraries) are copied to the
lib
directory:
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.1.1 https://maven.apache.org/xsd/assembly-2.1.1.xsd"> <id>zip</id> <includeBaseDirectory>true</includeBaseDirectory> <formats> <format>zip</format> <format>dir</format> </formats> <dependencySets> <dependencySet> <outputDirectory>lib</outputDirectory> </dependencySet> </dependencySets> </assembly>
You could also use the
Maven Dependency Plugin
(e.g. goal dependency:copy
or dependency:copy-dependencies
) or another Maven
plugin to do the same.