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.4.jar
flatlaf-3.4-linux-x86_64.so
flatlaf-3.4-macos-arm64.dylib
flatlaf-3.4-macos-x86_64.dylib
flatlaf-3.4-windows-x86_64.dll
flatlaf-3.4-windows-x86.dll
flatlaf-3.4-windows-arm64.dll
lib/flatlaf-3.4.jar
bin/flatlaf-3.4-linux-x86_64.so
bin/flatlaf-3.4-macos-arm64.dylib
bin/flatlaf-3.4-macos-x86_64.dylib
bin/flatlaf-3.4-windows-x86_64.dll
bin/flatlaf-3.4-windows-x86.dll
bin/flatlaf-3.4-windows-arm64.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-macos-arm64.dylib
myapp-1.0-flatlaf-macos-x86_64.dylib
myapp-1.0-flatlaf-windows-x86_64.dll
myapp-1.0-flatlaf-windows-x86.dll
myapp-1.0-flatlaf-windows-arm64.dll
lib/myapp-1.0.jar
bin/myapp-1.0-flatlaf-linux-x86_64.so
bin/myapp-1.0-flatlaf-macos-arm64.dylib
bin/myapp-1.0-flatlaf-macos-x86_64.dylib
bin/myapp-1.0-flatlaf-windows-x86_64.dll
bin/myapp-1.0-flatlaf-windows-x86.dll
bin/myapp-1.0-flatlaf-windows-arm64.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.4/
    flatlaf-3.4.jar
    flatlaf-3.4-no-natives.jar
    flatlaf-3.4-sources.jar
    flatlaf-3.4-javadoc.jar
    flatlaf-3.4-linux-x86_64.so
    flatlaf-3.4-macos-arm64.dylib
    flatlaf-3.4-macos-x86_64.dylib
    flatlaf-3.4-windows-x86_64.dll
    flatlaf-3.4-windows-x86.dll
    flatlaf-3.4-windows-arm64.dll

"no-natives" JAR v3.4

Besides flatlaf.jar (which contains FlatLaf native libraries), there is also flatlaf-no-natives.jar available on Maven Central (since FlatLaf 3.4). Both JARs contain the same files, except that flatlaf-no-natives.jar does not contain FlatLaf native libraries. This is useful if you sign your application. See macOS signing.

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.4"
    implementation( "com.formdev:flatlaf:${flatlafVersion}" )
    implementation( "com.formdev:flatlaf:${flatlafVersion}:linux-x86_64@so" )
    implementation( "com.formdev:flatlaf:${flatlafVersion}:macos-arm64@dylib" )
    implementation( "com.formdev:flatlaf:${flatlafVersion}:macos-x86_64@dylib" )
    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" )

    // ARM 64-bit (not needed if your application does not support Windows on ARM)
    implementation( "com.formdev:flatlaf:${flatlafVersion}:windows-arm64@dll" )
}

When running Gradle tasks installDist, distZip or distTar, the native libraries are copied to the same directory as the FlatLaf JAR.

"no-natives" JAR v3.4

dependencies {
    // FlatLaf "no-natives" JAR
    implementation("com.formdev:flatlaf:${flatlafVersion}:no-natives")

    // if using other FlatLaf libraries, it is required to exclude "com.formdev:flatlaf"
    implementation("com.formdev:flatlaf-extras:${flatlafVersion}") {
        exclude("com.formdev", "flatlaf")
    }
}

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.4</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>macos-arm64</classifier>
            <type>dylib</type>
        </dependency>
        <dependency>
            <groupId>com.formdev</groupId>
            <artifactId>flatlaf</artifactId>
            <version>${flatlafVersion}</version>
            <classifier>macos-x86_64</classifier>
            <type>dylib</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>

        <!-- ARM 64-bit (not needed if your application does not support Windows on ARM) -->
        <dependency>
            <groupId>com.formdev</groupId>
            <artifactId>flatlaf</artifactId>
            <version>${flatlafVersion}</version>
            <classifier>windows-arm64</classifier>
            <type>dll</type>
        </dependency>
    </dependencies>
</project>

"no-natives" JAR v3.4

    <dependencies>
        <!-- FlatLaf "no-natives" JAR -->
        <dependency>
            <groupId>com.formdev</groupId>
            <artifactId>flatlaf</artifactId>
            <version>${flatlafVersion}</version>
            <classifier>no-natives</classifier>
        </dependency>

        <!-- if using other FlatLaf libraries, it is required to exclude "com.formdev:flatlaf" -->
        <dependency>
            <groupId>com.formdev</groupId>
            <artifactId>flatlaf-extras</artifactId>
            <version>${flatlafVersion}</version>
            <exclusions>
                <exclusion>
                    <groupId>com.formdev</groupId>
                    <artifactId>flatlaf</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>

Assembly

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="https://maven.apache.org/ASSEMBLY/2.1.1"
          xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="https://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.

macOS signing

If you sign your macOS application using your certificate issued by Apple, then you also need to sign the two FlatLaf .dylib native libraries. It is recommended to use the "no-natives" JAR in this case.