title: "no lwjgl in java.library.path"
body: <p>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. I'll try to be as descriptive and informative as possible, so thank you for any responses ahead of time.</p>
  
  <p><strong>Objective:</strong> Create a project that depends on LWJGL (<em>Version 2.9.1</em>) in Eclipse(<em>Version: Luna Service Release 1 (4.4.1)</em>) using Maven 2 (<em>M2E 1.5.0 plugin</em>). </p>
  
  <p>So far, I've setup my project in Eclipse as a Maven project using M2E. </p>
  
  <p>I've setup my <code>pom.xml</code> after reading through various articles/posts that touch on the subject of Eclipse+Maven+LWJGL and it has turned out as such:</p>
  
  <pre><code>&lt;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"&gt;
  
  &lt;!-- Supported POM Version --&gt;
  &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
  &lt;!-- Project Information --&gt;
  &lt;groupId&gt;HIDDEN.GROUP.ID&lt;/groupId&gt;
  &lt;artifactId&gt;HIDDEN.ARTIFACT.ID&lt;/artifactId&gt;
  &lt;version&gt;0.1.0&lt;/version&gt;
  &lt;name&gt;HIDDEN.NAME&lt;/name&gt;
  &lt;description&gt;HIDDEN DESCRIPTION&lt;/description&gt;
  
  &lt;!-- Build Properties --&gt;
  &lt;properties&gt;
      &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
      &lt;lwjgl-version&gt;2.9.1&lt;/lwjgl-version&gt;
      &lt;main&gt;HIDDEN.MAIN.CLASS&lt;/main&gt;
  &lt;/properties&gt;
  
  &lt;!-- Dependencies --&gt;
  &lt;dependencies&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.lwjgl.lwjgl&lt;/groupId&gt;
          &lt;artifactId&gt;lwjgl&lt;/artifactId&gt;
          &lt;version&gt;${lwjgl-version}&lt;/version&gt;
          &lt;type&gt;jar&lt;/type&gt;
          &lt;scope&gt;compile&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.lwjgl.lwjgl&lt;/groupId&gt;
          &lt;artifactId&gt;lwjgl_util&lt;/artifactId&gt;
          &lt;version&gt;${lwjgl-version}&lt;/version&gt;
          &lt;type&gt;jar&lt;/type&gt;
          &lt;scope&gt;compile&lt;/scope&gt;
      &lt;/dependency&gt;
  &lt;/dependencies&gt;
  
  &lt;!-- Build Configuration --&gt;
  &lt;build&gt;
      &lt;finalName&gt;${project.name}&lt;/finalName&gt;
      &lt;defaultGoal&gt;clean package&lt;/defaultGoal&gt;
      &lt;sourceDirectory&gt;src&lt;/sourceDirectory&gt;
  
      &lt;!-- Resources --&gt;
      &lt;resources&gt;
          &lt;resource&gt;
              &lt;targetPath&gt;.&lt;/targetPath&gt;
              &lt;directory&gt;${basedir}/src/main/resources/&lt;/directory&gt;
              &lt;filtering&gt;true&lt;/filtering&gt;
              &lt;includes&gt;
                  &lt;!-- Include All HOCON Resources --&gt;
                  &lt;include&gt;*.config&lt;/include&gt;
              &lt;/includes&gt;
          &lt;/resource&gt;
      &lt;/resources&gt;
  
      &lt;!-- Plugins --&gt;
      &lt;plugins&gt;
  
          &lt;!-- Maven Compiler --&gt;
          &lt;plugin&gt;
              &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
              &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
              &lt;version&gt;2.4&lt;/version&gt;
              &lt;configuration&gt;
                  &lt;source&gt;1.8&lt;/source&gt;
                  &lt;target&gt;1.8&lt;/target&gt;
                  &lt;showDeprecation&gt;true&lt;/showDeprecation&gt;
              &lt;/configuration&gt;
          &lt;/plugin&gt;
  
          &lt;!-- Maven Shader --&gt;
          &lt;plugin&gt;
              &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
              &lt;artifactId&gt;maven-shade-plugin&lt;/artifactId&gt;
              &lt;version&gt;2.1&lt;/version&gt;
              &lt;executions&gt;
                  &lt;execution&gt;
                      &lt;phase&gt;package&lt;/phase&gt;
                      &lt;goals&gt;
                          &lt;goal&gt;shade&lt;/goal&gt;
                      &lt;/goals&gt;
                      &lt;configuration&gt;
                          &lt;artifactSet&gt;
                              &lt;includes&gt;
                                  &lt;include&gt;org.lwjgl.lwjgl:*&lt;/include&gt;
                              &lt;/includes&gt;
                          &lt;/artifactSet&gt;
                          &lt;transformers&gt;
                              &lt;transformer
                                  implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"&gt;
                                  &lt;manifestEntries&gt;
                                      &lt;Main-Class&gt;${main}&lt;/Main-Class&gt;
                                  &lt;/manifestEntries&gt;
                              &lt;/transformer&gt;
                          &lt;/transformers&gt;
                      &lt;/configuration&gt;
                  &lt;/execution&gt;
              &lt;/executions&gt;
          &lt;/plugin&gt;
  
          &lt;!-- Maven Natives --&gt;
          &lt;plugin&gt;
              &lt;groupId&gt;com.googlecode.mavennatives&lt;/groupId&gt;
              &lt;artifactId&gt;maven-nativedependencies-plugin&lt;/artifactId&gt;
              &lt;version&gt;0.0.6&lt;/version&gt;
              &lt;executions&gt;
                  &lt;execution&gt;
                      &lt;id&gt;unpacknatives&lt;/id&gt;
                      &lt;phase&gt;generate-resources&lt;/phase&gt;
                      &lt;goals&gt;
                          &lt;goal&gt;copy&lt;/goal&gt;
                      &lt;/goals&gt;
                  &lt;/execution&gt;
              &lt;/executions&gt;
          &lt;/plugin&gt;
      &lt;/plugins&gt;
      &lt;pluginManagement&gt;
          &lt;plugins&gt;
              &lt;!--This plugin's configuration is used to store Eclipse m2e settings 
                  only. It has no influence on the Maven build itself. --&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.eclipse.m2e&lt;/groupId&gt;
                  &lt;artifactId&gt;lifecycle-mapping&lt;/artifactId&gt;
                  &lt;version&gt;1.0.0&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;lifecycleMappingMetadata&gt;
                          &lt;pluginExecutions&gt;
                              &lt;pluginExecution&gt;
                                  &lt;pluginExecutionFilter&gt;
                                      &lt;groupId&gt;
                                          com.googlecode.mavennatives
                                      &lt;/groupId&gt;
                                      &lt;artifactId&gt;
                                          maven-nativedependencies-plugin
                                      &lt;/artifactId&gt;
                                      &lt;versionRange&gt;
                                          [0.0.5,)
                                      &lt;/versionRange&gt;
                                      &lt;goals&gt;
                                          &lt;goal&gt;copy&lt;/goal&gt;
                                      &lt;/goals&gt;
                                  &lt;/pluginExecutionFilter&gt;
                                  &lt;action&gt;
                                      &lt;ignore&gt;&lt;/ignore&gt;
                                  &lt;/action&gt;
                              &lt;/pluginExecution&gt;
                          &lt;/pluginExecutions&gt;
                      &lt;/lifecycleMappingMetadata&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/pluginManagement&gt;
  &lt;/build&gt;
  </code></pre>
  
  <p></p>
  
  <p><br/>
  For various reasons I have <em>hidden</em> certain portions of the above <code>pom.xml</code> (although it should not effect the diagnosis of my problem- just putting it out there, yes all of the above <em>hidden</em> "fields" are correctly typed and referenced. Although if you believe it may cause a problem, do inform me and I will check once again).</p>
  
  <p>Now, the <code>&lt;pluginManagement&gt;...&lt;/pluginManagement&gt;</code> section was automatically generated by Eclipse when:</p>
  
  <blockquote>
    <h2>Eclipse said (<a href="http://prntscr.com/4yuf1a" rel="nofollow noreferrer">screenshot</a>):</h2>
    
    <p>Plugin execution not covered by lifecycle configuration: com.googlecode.mavennatives:maven-nativedependencies-plugin:0.0.6:copy (execution: unpacknatives, phase: generate-resources)</p>
  </blockquote>
  
  <p><br/>
  To which I attempted to solve (it seems to have been solved) by clicking:</p>
  
  <blockquote>
    <h2>Eclipse said (<a href="http://prntscr.com/4yufe6" rel="nofollow noreferrer">screenshot</a>):</h2>
    
    <p>Permanently mark goal copy in pom.xml as ignored in Eclipse build</p>
  </blockquote>
  
  <p><br/>
  Which then generated the following code in the <code>pom.xml</code> (as seen above):</p>
  
  <pre><code> &lt;pluginManagement&gt;
          &lt;plugins&gt;
              &lt;!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.--&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.eclipse.m2e&lt;/groupId&gt;
                  &lt;artifactId&gt;lifecycle-mapping&lt;/artifactId&gt;
                  &lt;version&gt;1.0.0&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;lifecycleMappingMetadata&gt;
                          &lt;pluginExecutions&gt;
                              &lt;pluginExecution&gt;
                                  &lt;pluginExecutionFilter&gt;
                                      &lt;groupId&gt;
                                          com.googlecode.mavennatives
                                      &lt;/groupId&gt;
                                      &lt;artifactId&gt;
                                          maven-nativedependencies-plugin
                                      &lt;/artifactId&gt;
                                      &lt;versionRange&gt;
                                          [0.0.6,)
                                      &lt;/versionRange&gt;
                                      &lt;goals&gt;
                                          &lt;goal&gt;copy&lt;/goal&gt;
                                      &lt;/goals&gt;
                                  &lt;/pluginExecutionFilter&gt;
                                  &lt;action&gt;
                                      &lt;ignore&gt;&lt;/ignore&gt;
                                  &lt;/action&gt;
                              &lt;/pluginExecution&gt;
                          &lt;/pluginExecutions&gt;
                      &lt;/lifecycleMappingMetadata&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/pluginManagement&gt;
  </code></pre>
  
  <hr>
  
  <p><strong>Problem #1:</strong> </p>
  
  <p>So here's where I'm at with this. I can use <code>Project &gt; Run As &gt; Maven Build</code> to build my project (Goals: clean package) to which I get an executable JAR file with <code>lwjgl.jar</code>'s contents, <code>lwjgl_util.jar</code>'s contents, and what look to be like a few native files (<a href="http://prntscr.com/4yul1a" rel="nofollow noreferrer">screenshot</a>) shaded into the JAR as to create a standalone executable file. </p>
  
  <p>Running it wields a beautifully placed: 
  <br/>
  <code>Exception in thread "main" java.lang.UnsatisfiedLinkError: no lwjgl in java.library.path</code>.</p>
  
  <p>Okay, so I am aware that java is <em>not aware</em> of "lwjgl" in the system property <code>java.library.path</code>. Since LWJGL makes calls to the system property <code>java.library.path</code> in order to locate the native libraries (as I have read <a href="https://stackoverflow.com/a/24621172/4163852">here</a>) 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 <code>java.library.path</code>.</p>
  
  <p>I was able to get the JVM to properly run my JAR file with the following command through windows command prompt:
  <br/>
  <code>java -Djava.library.path=\exact\path\to\lwjgl-2.9.1\native\windows -jar \exact\path\to\&lt;project-name&gt;\target\&lt;project-name&gt;.jar</code></p>
  
  <p>This ran nicely. Although, I do <strong><em>not</em></strong> 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 <strong>very much</strong> appreciated). So say, they could be embedded under a folder named "/natives/lwjgl/" inside my JAR.</p>
  
  <hr>
  
  <p><strong>Problem #2:</strong> </p>
  
  <p>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). </p>
  
  <p>It causes the same error as above:
  <br/>
  <code>Exception in thread "main" java.lang.UnsatisfiedLinkError: no lwjgl in java.library.path</code>.</p>
  
  <p>Now, here's the difference though. I know a solution to this particular problem, it entails simply going through these quick steps:</p>
  
  <blockquote>
    <ul>
    <li><p>Project > Build Path > Configure Build Path...</p></li>
    <li><p>Click "Libraries" tab...</p></li>
    <li><p>Locate and select "lwjgl.jar" dependency...</p></li>
    <li><p>Open it's drop down and select "Native library location: (None)"...</p></li>
    <li><p>Click "edit"...</p></li>
    <li><p>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)</p></li>
    <li><p>Done!</p></li>
    </ul>
  </blockquote>
  
  <p>Although where my problem occurs is because I am using maven as my dependency management tool, the <code>lwjgl.jar</code> dependency in my Build Path (Libraries) for my project is located under "<em>Maven Dependencies</em>" (<a href="http://prntscr.com/4yukd3" rel="nofollow noreferrer">screenshot</a>).</p>
  
  <p>This prevents me from setting the 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)?</p>
  
  <hr>
  
  <p><em>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 <strong>many</strong> 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.</em></p>
  
  <hr>
  
  <p><strong>EDIT #1:</strong></p>
  
  <p>Solved problem #2 by adding the VM arguments "-Djava.library.path=target/natives" to the project's run configuration (<a href="http://prntscr.com/4yv03s" rel="nofollow noreferrer">screenshot</a>).</p>
  
  <p>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).</p>
  
  <p><strong>EDIT #2 (Oct 29th, 2014 - 6:30pm EST):</strong></p>
  
  <p>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.</p>