title: How to run nar file from command line?
body: <p>I used Eclipse and built a JNI project on my development machine using the <code>nar-maven</code> plugin. That compiles on multiple architectures and leaves me with <code>.nar</code> files.</p>
  
  <p>My problem is that now I want to run the main program in one of the Java classes in the <code>nar</code>.  I keep getting an <code>UnsatisfiedLinkError</code> when the Java program tries to load the native library that should be in the <code>nar</code> file. Now I realize that the <code>.so</code> file needs to be on the <code>java.library.path</code> but my problem is that I cannot see where to make that point since the only copy is somehow inside the <code>nar</code> file. I was under the impression that this would be handled behind the scenes because I'm using the auto-generated <code>NarSystem.loadLibrary</code> method in the Java.</p>
  
  <p>Details follow.</p>
  
  <p>The part of my POM configuring the <code>nar</code> plugin:</p>
  
  <pre><code>        &lt;plugin&gt;
              &lt;groupId&gt;com.github.maven-nar&lt;/groupId&gt;
              &lt;artifactId&gt;nar-maven-plugin&lt;/artifactId&gt;
              &lt;version&gt;3.5.1&lt;/version&gt;
              &lt;extensions&gt;true&lt;/extensions&gt;
              &lt;configuration&gt;
                  &lt;libraries&gt;
                      &lt;library&gt;
                          &lt;type&gt;jni&lt;/type&gt;
                          &lt;narSystemPackage&gt;com.myco.package&lt;/narSystemPackage&gt;
                      &lt;/library&gt;
                  &lt;/libraries&gt;
              &lt;/configuration&gt;
          &lt;/plugin&gt;
  </code></pre>
  
  <p>In one of my Java classes, I have a static initializer that calls the auto-generated method for loading the library:</p>
  
  <pre><code>static {
     com.myco.package.NarSystem.loadLibrary();
  }
  </code></pre>
  
  <p>After running <code>mvn install</code>, I have the following files in the appropriate sub-directory of my local <code>.m2/repository</code> directory:</p>
  
  <ul>
  <li><code>maven-metadata-local.xml</code></li>
  <li><code>_maven.repositories</code></li>
  <li><code>project-0.0.1-arm-Linux-gpp-jni.nar</code></li>
  <li><code>project-0.0.1.nar</code></li>
  <li><code>project-0.0.1.pom</code></li>
  <li><code>project-0.0.1-javadoc.jar</code></li>
  </ul>
  
  <p>I try to run from the command line with this command:</p>
  
  <pre><code>java -cp /home/myname/.m2/repository/com/myco/project/0.0.1/project-0.0.1.nar com.myco.package.MainClass
  </code></pre>
  
  <p>That begins to run the appropriate main program, so it found the Java portion. When it gets to the point where it should load the native library - the static block above - it throws the error</p>
  
  <pre><code>Exception in thread "main" java.lang.UnsatisfiedLinkError: no project-0.0.1 in java.library.path
  </code></pre>
  
  <p>This question, <a href="https://stackoverflow.com/questions/31920398/nar-dependency-in-multi-module-maven-project">Nar dependency in multi-module maven project</a>, looked like it would be close, but the answer depends on already having the native library "exposed" somehow.  I followed the questioner there trying <code>mvn nar:nar-unpack</code> and <code>mvn exec:java</code>, but that did not advance me. (Get the same apparently null result from the first as described in that question, and the same exception that I described here for the second.) </p>
  
  <p>Other questions considered:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/15646481/maven-unsatisfiedlinkerror-with-java-library-path">Maven - UnsatisfiedLinkError with java.library.path</a> Seems to be about finding libraries outside of the maven process. Answer given in terms of maven configuration files, which doesn't seem to help once I'm deployed.</li>
  <li><a href="https://stackoverflow.com/questions/20372228/maven-nar-plugin-and-tests-in-dependent-module">maven-nar-plugin and tests in dependent module</a> This deals with an issue specific to running tests.</li>
  <li><a href="https://stackoverflow.com/questions/30488701/nar-maven-plugin-and-native-library-loader-dont-load-native-lib">nar-maven-plugin and native-library-loader dont load native lib</a> This one is close but in any case has no answer. It seems to be different since that poster was trying to specify a library path on the command line somehow.</li>
  <li><a href="https://stackoverflow.com/questions/9628421/using-a-native-maven-artifact-nar-in-a-webapp">Using a native Maven artifact (nar) in a webapp</a> This one is about incorporating into a webapp, so it's different. It does seem to offer this clue: "Both of these are produced as NAR artifacts and require the maven-nar plugin in order to be used." But I haven't figured out how the plugin needs to be used!</li>
  </ul>
  
  <p>So how do I run this main program from the command line? If there's some pre-processing step to "extract" the native library what is it? If it's automatic, then what am I missing?  Thanks!</p>