How run a simple Java program with the client/server Nailgun (on Debian Stretch)?

我与影子孤独终老i 提交于 2020-03-22 06:45:07

问题


I'm try to use Nailgun on Debian GNU/Linux 9 (stretch).

"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."

Some documentation found:

  • Nailgun Quick Start
  • JVM Startup Times/Nailgun
  • How to improve performance of java using nailgun server
  • DSpace/Nailgun

I use Oracle Java version 10.0.2 (I also tried with GraalVM 1.0.0-rc9 Java 1.8.0_192).

A simple Java program to test: TestVarargs.java. (At the end I want to run a JAR file, but I had tried with this simple example because that doesn't work.)

$ wget https://bitbucket.org/OPiMedia/hellanguages/raw/default/Java/standard/TestVarargs/TestVarargs.java
$ javac TestVarargs.java
$ java TestVarargs

This program runs correctly.

First try, with the Debian nailgun package (version 0.9.1-3)

Installation:

$ sudo apt-get remove nailgun

Launch the server:

$ java -jar /usr/share/java/nailgun-server.jar &
NGServer 0.9.1 started on all interfaces, port 2113.

Run the client (/usr/bin/ng-nailgun):

$ ng-nailgun ng-version
NailGun server version 0.9.1

But the following doesn't work:

$ 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)

The stop command runs correctly:

$ 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.

Second try, building from GitHub sources

$ wget https://github.com/facebook/nailgun/archive/master.zip
$ unzip master.zip
$ cd nailgun-master

Compile the server with Maven:

$ mvn clean install
...
[INFO] BUILD SUCCESS
...

Compile the client:

$ make

Launch the server:

$ java -jar nailgun-server/target/nailgun-server-1.0.0.jar &
NGServer 1.0.0 started on all addresses, port 2113.

Run the client:

$ nailgun-client/target/ng ng-version
NailGun server version 1.0.0

But the following doesn't work:

$ nailgun-client/target/ng ng-cp

(Neither output nor error message.)

$ cd ..
$ nailgun-master/nailgun-client/target/ng TestVarargs

(Neither output nor error message.)

$ nailgun-master/nailgun-client/target/ng ng-alias TV TestVarargs

(Neither output nor error message.)

The stop command runs correctly:

$ nailgun-master/nailgun-client/target/ng ng-stop
NGServer shut down.

So, in conclusion, I can install and launch the server. But I can't run any Java program.


回答1:


Assume that your HelloWorld.class exists in the following directory:

/home/28041/ng-sample/com/crazyboy/HelloWorld.class

Before running the class, you need to tell where the class locates by using the following command:

ng ng-cp /home/28041/ng-sample

and then

ng com.crazyboy.HelloWorld


来源:https://stackoverflow.com/questions/53363931/how-run-a-simple-java-program-with-the-client-server-nailgun-on-debian-stretch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!