title: How run a simple Java program with the client/server Nailgun (on Debian Stretch)?
body: <p>I'm try to use <strong><a href="http://www.martiansoftware.com/nailgun/" rel="nofollow noreferrer">Nailgun</a></strong> on <strong>Debian GNU/Linux 9 (stretch)</strong>.</p>
  
  <p>"Nailgun is a client, protocol, and server for running Java programs from the command line without incurring the JVM startup overhead. Programs run in the server (which is implemented in Java), and are triggered by the client (written in C), which handles all I/O."</p>
  
  <p>Some documentation found:</p>
  
  <ul>
  <li><em><a href="http://www.martiansoftware.com/nailgun/quickstart.html" rel="nofollow noreferrer">Nailgun Quick Start</a></em></li>
  <li><em><a href="https://august.nagro.us/jvm-startup.html#nailgun" rel="nofollow noreferrer">JVM Startup Times/Nailgun</a></em></li>
  <li><em><a href="http://paramitech.com/how-to-improve-performance-of-java-using-nailgun-server/" rel="nofollow noreferrer">How to improve performance of java using nailgun server</a></em></li>
  <li><em><a href="https://wiki.duraspace.org/display/DSPACE/Nailgun" rel="nofollow noreferrer">DSpace/Nailgun</a></em></li>
  </ul>
  
  <p>I use <strong>Oracle Java version 10.0.2</strong> (I also tried with GraalVM 1.0.0-rc9 Java 1.8.0_192).</p>
  
  <p>A simple Java program to test:
  <a href="https://bitbucket.org/OPiMedia/hellanguages/src/default/Java/standard/TestVarargs/TestVarargs.java" rel="nofollow noreferrer">TestVarargs.java</a>.
  (At the end I want to run a JAR file, but I had tried with this simple example because that doesn't work.)</p>
  
  <pre><code>$ wget https://bitbucket.org/OPiMedia/hellanguages/raw/default/Java/standard/TestVarargs/TestVarargs.java
  $ javac TestVarargs.java
  $ java TestVarargs
  </code></pre>
  
  <p>This program runs correctly.</p>
  
  <h1>First try, with the <a href="https://packages.debian.org/stretch/nailgun" rel="nofollow noreferrer">Debian nailgun package</a> (version 0.9.1-3)</h1>
  
  <p>Installation:</p>
  
  <pre><code>$ sudo apt-get remove nailgun
  </code></pre>
  
  <p>Launch the server:</p>
  
  <pre><code>$ java -jar /usr/share/java/nailgun-server.jar &amp;
  NGServer 0.9.1 started on all interfaces, port 2113.
  </code></pre>
  
  <p>Run the client (<code>/usr/bin/ng-nailgun</code>):</p>
  
  <pre><code>$ ng-nailgun ng-version
  NailGun server version 0.9.1
  </code></pre>
  
  <p>But the following doesn't work:</p>
  
  <pre><code>$ ng-nailgun ng-cp
  java.lang.ClassCastException: java.base/jdk.internal.loader.ClassLoaders$AppClassLoader cannot be cast to java.base/java.net.URLClassLoader
      at com.martiansoftware.nailgun.builtins.NGClasspath.nailMain(NGClasspath.java:65)
      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.base/java.lang.reflect.Method.invoke(Method.java:564)
      at com.martiansoftware.nailgun.NGSession.run(NGSession.java:280)
  
  $ ng-nailgun TestVarargs
  java.lang.ClassNotFoundException: TestVarargs
      at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
      at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:190)
      at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:499)
      at java.base/java.lang.Class.forName0(Native Method)
      at java.base/java.lang.Class.forName(Class.java:291)
      at com.martiansoftware.nailgun.NGSession.run(NGSession.java:242)
  
  $ ng-nailgun ng-alias TV TestVarargs
  java.lang.ClassNotFoundException: TestVarargs
      at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
      at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:190)
      at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:499)
      at java.base/java.lang.Class.forName0(Native Method)
      at java.base/java.lang.Class.forName(Class.java:291)
      at com.martiansoftware.nailgun.builtins.NGAlias.nailMain(NGAlias.java:79)
      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.base/java.lang.reflect.Method.invoke(Method.java:564)
      at com.martiansoftware.nailgun.NGSession.run(NGSession.java:280)
  </code></pre>
  
  <p>The stop command runs correctly:</p>
  
  <pre><code>$ ng-nailgun ng-stop
  com.martiansoftware.nailgun.builtins.NGAlias: 2/0
  com.martiansoftware.nailgun.builtins.NGClasspath: 5/0
  com.martiansoftware.nailgun.builtins.NGServerStats: 0/0
  com.martiansoftware.nailgun.builtins.NGStop: 1/1
  com.martiansoftware.nailgun.builtins.NGVersion: 1/0
  NGServer shut down.
  </code></pre>
  
  <h1>Second try, building from <a href="https://github.com/facebook/nailgun" rel="nofollow noreferrer">GitHub sources</a></h1>
  
  <pre><code>$ wget https://github.com/facebook/nailgun/archive/master.zip
  $ unzip master.zip
  $ cd nailgun-master
  </code></pre>
  
  <p>Compile the server with Maven:</p>
  
  <pre><code>$ mvn clean install
  ...
  [INFO] BUILD SUCCESS
  ...
  </code></pre>
  
  <p>Compile the client:</p>
  
  <pre><code>$ make
  </code></pre>
  
  <p>Launch the server:</p>
  
  <pre><code>$ java -jar nailgun-server/target/nailgun-server-1.0.0.jar &amp;
  NGServer 1.0.0 started on all addresses, port 2113.
  </code></pre>
  
  <p>Run the client:</p>
  
  <pre><code>$ nailgun-client/target/ng ng-version
  NailGun server version 1.0.0
  </code></pre>
  
  <p>But the following doesn't work:</p>
  
  <pre><code>$ nailgun-client/target/ng ng-cp
  </code></pre>
  
  <p>(Neither output nor error message.)</p>
  
  <pre><code>$ cd ..
  $ nailgun-master/nailgun-client/target/ng TestVarargs
  </code></pre>
  
  <p>(Neither output nor error message.)</p>
  
  <pre><code>$ nailgun-master/nailgun-client/target/ng ng-alias TV TestVarargs
  </code></pre>
  
  <p>(Neither output nor error message.)</p>
  
  <p>The stop command runs correctly:</p>
  
  <pre><code>$ nailgun-master/nailgun-client/target/ng ng-stop
  NGServer shut down.
  </code></pre>
  
  <h2>So, in conclusion, I can install and launch the server. But I can't run any Java program.</h2>