title: How to Deploy a jar onto Raspberry Pi 2 using Maven Plugin
body: <p>I have a simple java class using Pi4J that contains a main method. I want to build and deploy it to a Raspberry Pi. I'm using java 8 on a windows 10 and my IDE is NetBeans 8.1. If the project is set up to be a normal (non-Maven) Java Application and set up to deploy to the Raspberry Pi via the NetBeans build configurations as shown <a href="https://netbeans.org/kb/docs/java/javase-embedded.html" rel="nofollow">here</a>, the project will build normal and FTP over the jar and then run it with no issues. 
  I would like to do the same but using Maven. The problem is that the code that is being ran has C code native to the ARM's architecture of the Pi and the Maven plugin I'm using seems to run the jar on my local box first in which the C code will crash throwing the Exception</p>
  
  <blockquote>
    <p>SEVERE: Unable to load [libpi4j.so] using path: [/lib/libpi4j.so]
    java.lang.IllegalArgumentException: The path has to be absolute, but found: \lib\libpi4j.so
        at com.pi4j.util.NativeLibraryLoader.loadLibraryFromClasspath(NativeLibraryLoader.java:120)
        at com.pi4j.util.NativeLibraryLoader.load(NativeLibraryLoader.java:92)
        at com.pi4j.wiringpi.Gpio.(Gpio.java:174)
        at com.pi4j.io.gpio.RaspiGpioProvider.(RaspiGpioProvider.java:51)
        at com.pi4j.io.gpio.GpioFactory.getDefaultProvider(GpioFactory.java:106)
        at com.pi4j.io.gpio.impl.GpioControllerImpl.(GpioControllerImpl.java:54)
        at com.pi4j.io.gpio.GpioFactory.getInstance(GpioFactory.java:89)
        at com.hadronix.pi4jsample2.ControlGpioExample.main(ControlGpioExample.java:24)</p>
    
    <p>Exception in thread "main" java.lang.UnsatisfiedLinkError:
    com.pi4j.wiringpi.Gpio.wiringPiSetup()I   at
    com.pi4j.wiringpi.Gpio.wiringPiSetup(Native Method)   at
    com.pi4j.io.gpio.RaspiGpioProvider.(RaspiGpioProvider.java:51)
      at
    com.pi4j.io.gpio.GpioFactory.getDefaultProvider(GpioFactory.java:106)
      at
    com.pi4j.io.gpio.impl.GpioControllerImpl.(GpioControllerImpl.java:54)
      at com.pi4j.io.gpio.GpioFactory.getInstance(GpioFactory.java:89)    at
    com.hadronix.pi4jsample2.ControlGpioExample.main(ControlGpioExample.java:24)</p>
  </blockquote>
  
  <p>If i just do a clean build, it will build fine and create the jar. However, if i choose to run the build then thats where the crash happens. This is the Maven plugin I'm using to deploy the jar to the Pi.</p>
  
  <pre><code>&lt;!-- OPTIONALLY DEPLOY THE FINAL JAR TO THE RASPBERRY PI --&gt;
          &lt;plugin&gt;
              &lt;artifactId&gt;maven-antrun-plugin&lt;/artifactId&gt;
              &lt;executions&gt;
  
                  &lt;!-- copy the compiled JAR file to the Raspberry Pi platform platform --&gt;
                  &lt;execution&gt;
                      &lt;id&gt;ControlGpioExample.jar&lt;/id&gt;
                      &lt;phase&gt;install&lt;/phase&gt;
                      &lt;goals&gt;
                          &lt;goal&gt;run&lt;/goal&gt;
                      &lt;/goals&gt;
                      &lt;configuration&gt;
                          &lt;tasks&gt;
                              &lt;taskdef resource="net/sf/antcontrib/antcontrib.properties"
                                       classpathref="maven.plugin.classpath" /&gt;
                              &lt;if&gt;
                                  &lt;equals arg1="${pi.transfer.dev}" arg2="true" /&gt;
                                  &lt;then&gt;
                                      &lt;!-- ensure the target directory exists on the Raspberry Pi --&gt;
                                      &lt;sshexec host="${pi.host.dev}" port="${pi.port.dev}" username="${pi.user.dev}"
                                                                                       password="${pi.password.dev}" trust="true" failonerror="false"
                                                                                       verbose="true" command="mkdir --parents ${pi.dirCopyTo.dev}" /&gt;
                                      &lt;!-- copy the JAR file to the Raspberry Pi --&gt;
                                      &lt;scp
                                          file="${project.build.directory}/${project.build.finalName}.jar"
                                          todir="${pi.user.dev}:${pi.password.dev}@${pi.host.dev}:${pi.dirCopyTo.dev}"
                                          port="${pi.port.dev}" trust="true" verbose="true" failonerror="true"&gt;
                                      &lt;/scp&gt;
                                  &lt;/then&gt;
                              &lt;/if&gt;
                          &lt;/tasks&gt;
                      &lt;/configuration&gt;
                  &lt;/execution&gt;
              &lt;/executions&gt;
              &lt;dependencies&gt;
                  &lt;dependency&gt;
                      &lt;groupId&gt;org.apache.ant&lt;/groupId&gt;
                      &lt;artifactId&gt;ant-jsch&lt;/artifactId&gt;
                      &lt;version&gt;${ant-jsch.version}&lt;/version&gt;
                  &lt;/dependency&gt;
                  &lt;dependency&gt;
                      &lt;groupId&gt;com.jcraft&lt;/groupId&gt;
                      &lt;artifactId&gt;jsch&lt;/artifactId&gt;
                      &lt;version&gt;${jsch.version}&lt;/version&gt;
                  &lt;/dependency&gt;
                  &lt;dependency&gt;
                      &lt;groupId&gt;ant-contrib&lt;/groupId&gt;
                      &lt;artifactId&gt;ant-contrib&lt;/artifactId&gt;
                      &lt;version&gt;${ant-contrib.version}&lt;/version&gt;
                  &lt;/dependency&gt;
              &lt;/dependencies&gt;
          &lt;/plugin&gt;
  </code></pre>
  
  <p>I'm trying to figure out how to change this plugin to not execute the code first on my local machine. I just want it to assume the jar is built, ssh into the remote Pi and copy the jar over and then run it there. Also, if someone has a completely better way while using Maven then I'm open to suggestions. Any help would be great!</p>
  
  <p>Here are links to what I'm using as references
  <a href="http://artem.gratchev.com/2015/03/java-application-jar-raspberry-pi-maven-eclipse/" rel="nofollow">link</a> 1</p>
  
  <p>Thanks in advance.</p>