我尝试在 Debian GNU / Linux 9(拉伸)上使用 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
该程序正常运行。
安装:
$ 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.
$ 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.
答案 0 :(得分:1)
假设您的HelloWorld.class
位于以下目录中:
/home/28041/ng-sample/com/crazyboy/HelloWorld.class
在运行该类之前,您需要使用以下命令来告知该类的位置:
ng ng-cp /home/28041/ng-sample
然后
ng com.crazyboy.HelloWorld