运行简单的Java程序

运行简单的Java程序

本文介绍了如何使用客户端/服务器Nailgun(在Debian Stretch上)运行简单的Java程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在上使用 Nailgun Debian GNU/Linux 9(拉伸).

"Nailgun是一种客户端,协议和服务器,用于从命令行运行Java程序而不会引起JVM启动开销.程序在服务器(以Java实现)中运行,并由客户端触发(以C),它处理所有I/O."

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

找到了一些文档:

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

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

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

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

该程序正常运行.

安装:

$ 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命令正确运行:

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.

第二次尝试,从 GitHub来源构建

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

使用Maven编译服务器:

Compile the server with 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

(既不输出也不显示错误消息.)

(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.)

stop命令正确运行:

The stop command runs correctly:

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

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

推荐答案

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

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

然后

ng com.crazyboy.HelloWorld

这篇关于如何使用客户端/服务器Nailgun(在Debian Stretch上)运行简单的Java程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 20:12