简体   繁体   English

Maven将本机添加到库路径

[英]Maven add natives to library path

I want to include LWJGL via Maven in my project. 我希望在我的项目中通过Maven包含LWJGL。 I get the .jar files but the natives are not in the classpath. 我得到.jar文件,但本机不在类路径中。

With the help of google I found out that I should use mavennatives in order to automatically extract and copy the natives. 在谷歌的帮助下,我发现我应该使用mavennatives来自动提取和复制本机。 However mavennatives will only find the natives that start with native- and the LWJGL-natives all have names like {artifactId}-{version}-natives-{os}.jar . 然而mavennatives只能找到下手当地人native-和LWJGL本地人所有名称类似{artifactId}-{version}-natives-{os}.jar

Question : How can I get Maven to import the dependencies with the proper names and extract these natives? 问题 :如何让Maven使用正确的名称导入依赖项并提取这些本机?

My pom.xml : 我的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>

From official documentation of the plugin: 从插件的官方文档

This plugin unpacks every dependency with a classifier beginning with natives- . 这个插件使用以natives-开头的分类器解包每个依赖natives-

That's exactly your use case, the documentation points to the classifier element, which in your case is natives-linux or natives-windows . 这正是你的用例,文档指向分类器元素,在你的情况下是natives-linuxnatives-windows

Accordingo to the documentation, theses cases will be handled: 根据文件,这些案件将被处理:

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 ) 这是默认值,当启用separateDirs时,插件会将每个本机依赖项解压缩到nativesTargetDir的子目录,其名称与其分类器相同(例如: natives-windows将转到target/natives/windows

Indeed the whole library's jar is in the form of {artifactId}-{version}-natives-{os}.jar but in Maven the classifier is exactly the string between the {version} and the extension of the file: in this case natives-{os} , which starts by natives and as such is handled by the library. 实际上整个库的jar都是{artifactId}-{version}-natives-{os}.jar但是在Maven中,分类器正是{version}和文件扩展名之间的字符串:在本例中是natives-{os} ,开始由natives并且这样被库处理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM