简体   繁体   English

“ java.library.path中没有lwjgl”

[英]“no lwjgl in java.library.path”

In looking around and reading other similar posts, I've been unable to solve a problem I've been having with LWJGL as a dependency. 在环顾四周并阅读其他类似文章时,我一直无法解决将LWJGL作为依赖项所遇到的问题。 I'll try to be as descriptive and informative as possible, so thank you for any responses ahead of time. 我会尽力做到描述性和信息性,因此,感谢您提前提出答复。

Objective: Create a project that depends on LWJGL ( Version 2.9.1 ) in Eclipse( Version: Luna Service Release 1 (4.4.1) ) using Maven 2 ( M2E 1.5.0 plugin ). 目标:使用Maven 2( M2E 1.5.0插件 )在Eclipse( 版本:Luna Service Release 1(4.4.1) )中创建依赖于LWJGL( 2.9.1 )的项目。

So far, I've setup my project in Eclipse as a Maven project using M2E. 到目前为止,我已经设置我的Eclipse项目为使用M2E Maven项目。

I've setup my pom.xml after reading through various articles/posts that touch on the subject of Eclipse+Maven+LWJGL and it has turned out as such: 在阅读了涉及Eclipse + Maven + LWJGL主题的各种文章/文章之后,我已经设置了pom.xml ,结果如下:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<!-- Supported POM Version -->
<modelVersion>4.0.0</modelVersion>

<!-- Project Information -->
<groupId>HIDDEN.GROUP.ID</groupId>
<artifactId>HIDDEN.ARTIFACT.ID</artifactId>
<version>0.1.0</version>
<name>HIDDEN.NAME</name>
<description>HIDDEN DESCRIPTION</description>

<!-- Build Properties -->
<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <lwjgl-version>2.9.1</lwjgl-version>
    <main>HIDDEN.MAIN.CLASS</main>
</properties>

<!-- Dependencies -->
<dependencies>
    <dependency>
        <groupId>org.lwjgl.lwjgl</groupId>
        <artifactId>lwjgl</artifactId>
        <version>${lwjgl-version}</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.lwjgl.lwjgl</groupId>
        <artifactId>lwjgl_util</artifactId>
        <version>${lwjgl-version}</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
</dependencies>

<!-- Build Configuration -->
<build>
    <finalName>${project.name}</finalName>
    <defaultGoal>clean package</defaultGoal>
    <sourceDirectory>src</sourceDirectory>

    <!-- Resources -->
    <resources>
        <resource>
            <targetPath>.</targetPath>
            <directory>${basedir}/src/main/resources/</directory>
            <filtering>true</filtering>
            <includes>
                <!-- Include All HOCON Resources -->
                <include>*.config</include>
            </includes>
        </resource>
    </resources>

    <!-- Plugins -->
    <plugins>

        <!-- Maven Compiler -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
                <showDeprecation>true</showDeprecation>
            </configuration>
        </plugin>

        <!-- Maven Shader -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>2.1</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <artifactSet>
                            <includes>
                                <include>org.lwjgl.lwjgl:*</include>
                            </includes>
                        </artifactSet>
                        <transformers>
                            <transformer
                                implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                <manifestEntries>
                                    <Main-Class>${main}</Main-Class>
                                </manifestEntries>
                            </transformer>
                        </transformers>
                    </configuration>
                </execution>
            </executions>
        </plugin>

        <!-- Maven Natives -->
        <plugin>
            <groupId>com.googlecode.mavennatives</groupId>
            <artifactId>maven-nativedependencies-plugin</artifactId>
            <version>0.0.6</version>
            <executions>
                <execution>
                    <id>unpacknatives</id>
                    <phase>generate-resources</phase>
                    <goals>
                        <goal>copy</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
    <pluginManagement>
        <plugins>
            <!--This plugin's configuration is used to store Eclipse m2e settings 
                only. It has no influence on the Maven build itself. -->
            <plugin>
                <groupId>org.eclipse.m2e</groupId>
                <artifactId>lifecycle-mapping</artifactId>
                <version>1.0.0</version>
                <configuration>
                    <lifecycleMappingMetadata>
                        <pluginExecutions>
                            <pluginExecution>
                                <pluginExecutionFilter>
                                    <groupId>
                                        com.googlecode.mavennatives
                                    </groupId>
                                    <artifactId>
                                        maven-nativedependencies-plugin
                                    </artifactId>
                                    <versionRange>
                                        [0.0.5,)
                                    </versionRange>
                                    <goals>
                                        <goal>copy</goal>
                                    </goals>
                                </pluginExecutionFilter>
                                <action>
                                    <ignore></ignore>
                                </action>
                            </pluginExecution>
                        </pluginExecutions>
                    </lifecycleMappingMetadata>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
</build>


For various reasons I have hidden certain portions of the above pom.xml (although it should not effect the diagnosis of my problem- just putting it out there, yes all of the above hidden "fields" are correctly typed and referenced. Although if you believe it may cause a problem, do inform me and I will check once again). 由于种种原因,我已经隐藏了上面pom.xml某些部分(尽管它不会影响我的问题的诊断-只是将其放在那里,是的,所有上述隐藏的 “字段”都是正确键入和引用的。认为这可能会导致问题,请通知我,我会再次检查)。

Now, the <pluginManagement>...</pluginManagement> section was automatically generated by Eclipse when: 现在,Eclipse在以下情况下自动生成<pluginManagement>...</pluginManagement>部分:

Eclipse said ( screenshot ): Eclipse说( 截图 ):

Plugin execution not covered by lifecycle configuration: com.googlecode.mavennatives:maven-nativedependencies-plugin:0.0.6:copy (execution: unpacknatives, phase: generate-resources) 生命周期配置未涵盖插件执行:com.googlecode.mavennatives:maven-nativedependencies-plugin:0.0.6:copy(执行:unpacknatives,阶段:generate-resources)


To which I attempted to solve (it seems to have been solved) by clicking: 我尝试通过以下方法解决(似乎已解决)的问题:

Eclipse said ( screenshot ): Eclipse说( 截图 ):

Permanently mark goal copy in pom.xml as ignored in Eclipse build 将pom.xml中的目标副本永久标记为在Eclipse构建中被忽略


Which then generated the following code in the pom.xml (as seen above): 然后在pom.xml生成以下代码(如上所示):

 <pluginManagement>
        <plugins>
            <!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
            <plugin>
                <groupId>org.eclipse.m2e</groupId>
                <artifactId>lifecycle-mapping</artifactId>
                <version>1.0.0</version>
                <configuration>
                    <lifecycleMappingMetadata>
                        <pluginExecutions>
                            <pluginExecution>
                                <pluginExecutionFilter>
                                    <groupId>
                                        com.googlecode.mavennatives
                                    </groupId>
                                    <artifactId>
                                        maven-nativedependencies-plugin
                                    </artifactId>
                                    <versionRange>
                                        [0.0.6,)
                                    </versionRange>
                                    <goals>
                                        <goal>copy</goal>
                                    </goals>
                                </pluginExecutionFilter>
                                <action>
                                    <ignore></ignore>
                                </action>
                            </pluginExecution>
                        </pluginExecutions>
                    </lifecycleMappingMetadata>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>

Problem #1: 问题1:

So here's where I'm at with this. 所以这就是我在这里。 I can use Project > Run As > Maven Build to build my project (Goals: clean package) to which I get an executable JAR file with lwjgl.jar 's contents, lwjgl_util.jar 's contents, and what look to be like a few native files ( screenshot ) shaded into the JAR as to create a standalone executable file. 我可以使用“ Project > Run As > Maven Build来构建我的项目(目标:干净的程序包),并获得一个包含lwjgl.jar的内容, lwjgl_util.jar的内容以及外观的可执行JAR文件。仅有很少的本机文件( 屏幕截图 )隐藏在JAR中,以创建独立的可执行文件。

Running it wields a beautifully placed: 运行它会产生一个精美的位置:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no lwjgl in java.library.path . Exception in thread "main" java.lang.UnsatisfiedLinkError: no lwjgl in java.library.path

Okay, so I am aware that java is not aware of "lwjgl" in the system property java.library.path . 好的,所以我知道java在系统属性java.library.path 不知道 “ lwjgl”。 Since LWJGL makes calls to the system property java.library.path in order to locate the native libraries (as I have read here ) I am lead to believe that I must now get the path to the required native libraries for the system running this JAR file into the system property java.library.path . 由于LWJGL调用了系统属性java.library.path来定位本机库(如我在此处所读),因此我相信我现在必须获取运行此JAR的系统所需的本机库的路径。文件放入系统属性java.library.path

I was able to get the JVM to properly run my JAR file with the following command through windows command prompt: 我可以通过Windows命令提示符使用以下命令来使JVM正确运行我的JAR文件:
java -Djava.library.path=\\exact\\path\\to\\lwjgl-2.9.1\\native\\windows -jar \\exact\\path\\to\\<project-name>\\target\\<project-name>.jar

This ran nicely. 运行得很好。 Although, I do not want to have to specify the location of the native files manually. 虽然,我希望有手动指定本机文件的位置。 Ideally, what I'm looking for is to have the native files embedded in the JAR (they are partially but I have a feeling they're not all of them), selected at run-time based on the user's operating system, and simply set (suggestions/help on how to do so is very much appreciated). 理想情况下,我要寻找的是将本地文件嵌入到JAR中(它们是部分文件,但我感觉它们并不是全部),并在运行时根据用户的操作系统进行选择,并且简单设置( 非常感谢您的建议/帮助)。 So say, they could be embedded under a folder named "/natives/lwjgl/" inside my JAR. 可以这么说,它们可以嵌入到我的JAR中名为“ / natives / lwjgl /”的文件夹下。


Problem #2: 问题2:

This problem is the same as the first, although it is not caused by a compiled JAR, but instead when attempting to run my main class through my IDE (Eclipse). 这个问题与第一个问题相同,尽管它不是由已编译的JAR引起的,而是尝试通过IDE(Eclipse)运行主类时引起的。

It causes the same error as above: 它导致与上述相同的错误:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no lwjgl in java.library.path . Exception in thread "main" java.lang.UnsatisfiedLinkError: no lwjgl in java.library.path

Now, here's the difference though. 现在,这就是区别。 I know a solution to this particular problem, it entails simply going through these quick steps: 我知道解决此特定问题的方法,它只需完成以下快速步骤即可:

  • Project > Build Path > Configure Build Path... 项目>构建路径>配置构建路径...

  • Click "Libraries" tab... 点击“库”标签...

  • Locate and select "lwjgl.jar" dependency... 找到并选择“ lwjgl.jar”依赖项...

  • Open it's drop down and select "Native library location: (None)"... 打开它的下拉菜单,然后选择“本地库位置:(无)” ...

  • Click "edit"... 点击“编辑” ...

  • Fill in field with the correct URI to the natives folder for LWJGL that corresponds with your OS (in my case it's /natives/windows) 在正确的URI字段中填写与您的操作系统相对应的LWJGL的natives文件夹(在我的情况下是/ natives / windows)

  • Done! 完成!

Although where my problem occurs is because I am using maven as my dependency management tool, the lwjgl.jar dependency in my Build Path (Libraries) for my project is located under " Maven Dependencies " ( screenshot ). 尽管发生问题的原因是因为我将maven用作依赖项管理工具,但我的项目的构建路径(库)中的lwjgl.jar依赖项位于“ Maven Dependencies ”下( 屏幕截图 )。

This prevents me from setting the URI. 这使我无法设置URI。 It simply does not get set (or just doesn't save). 它只是没有设置(或只是不保存)。 So my question here is, am I doing something wrong? 所以我的问题是,我做错了什么吗? Or must I take another approach due to using maven (m2e plugin)? 还是由于使用Maven(m2e插件)而必须采取另一种方法?


Thank you very much for reading and helping me out for either of my problems! 非常感谢您阅读和帮助我解决我的任何一个问题! I put both in this one post as the second problem is basically the first but just a variation (sorta) so I feel making two posts would be useless. 我把这两个问题都放在了这两个职位上,因为第二个问题基本上是第一个,但只是一个变体(排序),所以我觉得写两个职位将毫无用处。 I know this may be a duplicate of many others, but I was unable to find the help that corresponded to my particular situation(s). 我知道这可能是许多其他产品的复制品,但是我找不到适合于我的特定情况的帮助。 If you need any details or information in particular that I have left out or that you feel I should elaborate on please just ask and I'll be more than willing to provide. 如果您特别需要我遗漏的任何细节或信息,或者您觉得我应该详细说明,请询问,我将乐意提供。


EDIT #1: 编辑#1:

Solved problem #2 by adding the VM arguments "-Djava.library.path=target/natives" to the project's run configuration ( screenshot ). 通过将VM参数“ -Djava.library.path = target / natives”添加到项目的运行配置( 屏幕截图 ),解决了问题2。

Although I still have the issue where the compiled JAR can not be executed (I would like to solve it universally and not specifically for my machine as this is to be distributed to Windows/Mac/Linux consumers in the end). 尽管仍然存在无法执行已编译JAR的问题(我想普遍解决该问题,而不是专门针对我的机器,因为最终将分发给Windows / Mac / Linux用户)。

EDIT #2 (Oct 29th, 2014 - 6:30pm EST): 编辑2(2014年10月29日-美国东部标准时间下午6:30):

I've been able to create batch files to run the program, although that is obviously platform dependant and not what I'm going for. 我已经能够创建批处理文件来运行该程序,尽管这显然取决于平台,而不是我想要的。 Any help on getting the system property set would be much appreciated. 任何获得系统属性集的帮助将不胜感激。

as u already found out, it happens when ur IDE cannot locate the natives of lwjgl. 正如您已经发现的那样,当您的IDE无法找到lwjgl的本机时,就会发生这种情况。

I would like to suggest to follow these steps if u didnt already do that. 如果您还没有这样做,我建议您遵循以下步骤。 It all depends on your pom.xml and ur configuration of java.library.path! 这完全取决于您的pom.xml和您对java.library.path的配置!

If this doesnt work i could try to troubleshoot more. 如果这不起作用,我可以尝试解决更多问题。 However in my case it solved the problem. 但是就我而言,它解决了问题。

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

相关问题 ant和“ java.library.path中没有lwjgl” - ant & “no lwjgl in java.library.path” java.library.path中没有lwjgl-Netbeans - no lwjgl in java.library.path - Netbeans Eclipse java lwjgl java.library.path中没有lwjgl - Eclipse java lwjgl no lwjgl in java.library.path LWJGL&#39;java.lang.UnsatisfiedLinkError&#39;:java.library.path中没有lwjgl - LWJGL 'java.lang.UnsatisfiedLinkError': no lwjgl in java.library.path 获取“java.lang.UnsatisfiedLinkError”:java.library.path 中没有 lwjgl - Getting 'java.lang.UnsatisfiedLinkError': no lwjgl in java.library.path LWJGL Applet java.lang.UnsatisfiedLinkError:java.library.path中没有lwjgl - LWJGL Applet java.lang.UnsatisfiedLinkError: no lwjgl in java.library.path LWJGL程序给出错误“ java.library.path中没有lwjgl”,但是当我在清单中查找时 - LWJGL program gives error “no lwjgl in java.library.path”, yet when I look in the manifest it is there 臭名昭著的“java.lang.UnsatisfiedLinkError:java.library.path 中没有 lwjgl64” - Infamous "java.lang.UnsatisfiedLinkError: no lwjgl64 in java.library.path" 线程“ main”中的异常java.lang.UnsatisfiedLinkError:java.library.path中没有lwjgl-devil - Exception in thread “main” java.lang.UnsatisfiedLinkError: no lwjgl-devil in java.library.path java.lang.UnsatisfiedLinkError:java.library.path中没有lwjgl,但是设置了本机 - java.lang.UnsatisfiedLinkError: no lwjgl in java.library.path but natives are set
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM