Maven 将 natives 添加到库路径

Maven add natives to library path

我想通过 Maven 在我的项目中包含 LWJGL。我得到了 .jar 文件,但本地人不在类路径中。

在 google 的帮助下,我发现我应该使用 mavennatives 来自动提取和复制本地人。但是 mavennatives 只会找到以 native- 开头的本地人,而 LWJGL 本地人的名字都像 {artifactId}-{version}-natives-{os}.jar.

问题:如何让 Maven 导入具有正确名称的依赖项并提取这些 natives?

我的pom.xml:

<project ... >
     ...
    <build>
        <plugins>
            ...
            <plugin>
                <groupId>com.googlecode.mavennatives</groupId>
                <artifactId>maven-nativedependencies-plugin</artifactId>
                <version>0.0.7</version>
                <executions>
                    <execution>
                        <id>unpacknatives</id>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        ...
        <dependency>
            <groupId>org.lwjgl</groupId>
            <artifactId>lwjgl</artifactId>
            <version>3.0.0a</version>
        </dependency>
        <dependency>
            <groupId>org.lwjgl</groupId>
            <artifactId>lwjgl-platform</artifactId>
            <version>3.0.0a</version>
            <classifier>natives-linux</classifier>
        </dependency>
        <dependency>
            <groupId>org.lwjgl</groupId>
            <artifactId>lwjgl-platform</artifactId>
            <version>3.0.0a</version>
            <classifier>natives-windows</classifier>
        </dependency>
    </dependencies>
</project>

来自插件的official documentation

This plugin unpacks every dependency with a classifier beginning with natives-.

这正是您的用例,文档指向 classifier 元素,在您的情况下是 natives-linuxnatives-windows.

根据文档,这些案例将被处理:

This are the default values, when enabling separateDirs the plugin will unpack each native dependency to a subdir of the nativesTargetDir named like its classifier (for example: natives-windows will go to target/natives/windows)

事实上,整个库的 jar 都是 {artifactId}-{version}-natives-{os}.jar 的形式,但在 Maven 中,分类器恰好是 {version} 和文件扩展名之间的字符串:在这种情况下 natives-{os},它以 natives 开头,因此由图书馆处理。