3

我正在尝试在Debian GNU/Linux 9 (stretch)上使用Nailgun

“Nailgun 是一个客户端、协议和服务器,用于从命令行运行 Java 程序而不会产生 JVM 启动开销。程序在服务器中运行(用 Java 实现),并由客户端触发(用 C 编写),它处理所有 I/O。”

发现一些文档:

我使用Oracle Java 版本 10.0.2(我也尝试使用 GraalVM 1.0.0-rc9 Java 1.8.0_192)。

一个简单的 Java 测试程序: TestVarargs.java。(最后我想运行一个 JAR 文件,但我尝试过这个简单的例子,因为这不起作用。)

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

该程序运行正常。

首先尝试使用Debian nailgun 软件包(版本 0.9.1-3)

安装:

$ sudo apt-get remove nailgun

启动服务器:

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

运行客户端 ( /usr/bin/ng-nailgun):

$ ng-nailgun ng-version
NailGun server version 0.9.1

但以下不起作用:

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

stop 命令运行正确:

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

第二次尝试,从GitHub 源构建

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

使用 Maven 编译服务器:

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

编译客户端:

$ make

启动服务器:

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

运行客户端:

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

但以下不起作用:

$ nailgun-client/target/ng ng-cp

(既没有输出也没有错误消息。)

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

(既没有输出也没有错误消息。)

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

(既没有输出也没有错误消息。)

stop 命令运行正确:

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

所以,总而言之,我可以安装和启动服务器。但我无法运行任何 Java 程序。

4

1 回答 1

2

假设您HelloWorld.class存在于以下目录中:

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

在运行类之前,您需要使用以下命令告诉类的位置:

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

接着

ng com.crazyboy.HelloWorld
于 2019-05-16T05:17:13.553 回答