如何使用 Nailgun Server 启动 Groovy 脚本(或 Java 类)
我正在开发一个频繁启动的 Groovy shell 脚本(执行相当小的任务),因此我需要快速的 JVM 启动时间。为了实现这一目标,我尝试使用 Nailgun 启动它。
我已将 Nailgun 作为 Ubuntu 软件包安装。然后我通过链接 /usr 修复了 参数错误 /bin/ng-server
到 /usr/bin/ng
。我像这样启动 Nailgun-Server:
java -cp /usr/share/java/nailgun-0.7.1.jar -server com.martiansoftware.nailgun.NGServer
我有一个名为 hello.groovy 的简单虚拟 Groovy 脚本,只是为了测试nailgun-server:
#!/usr/bin/env groovy
def sayHello() {
println("Hello Groovy!");
}
sayHello();
我使用 groovyc 将文件编译为 hello.class。
现在我想在 Nailgun 服务器中启动该脚本。我的幼稚方法是:
ng hello
ng hello.sayHello
但我得到的只是 ClassNotFoundExceptions:
java.lang.ClassNotFoundException: hello
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at com.martiansoftware.nailgun.NGSession.run(Unknown Source)
那么,使用 Nailgun 服务器启动 Groovy 脚本的正确方法是什么?我也很欣赏一些关于如何使用 Nailgun 的好网站/教程,真的很难获得任何如何使用它的信息...
编辑:
我也很欣赏一个完整的示例(包括如何使用 ng 调用特定类),以便将nailgun 与纯 Java 类一起使用,因为我也无法让 ng 与任何 Java 类一起使用。
I'm developing a Groovy shell script which is launched frequently (doing rather small tasks), therefore I need a fast JVM startup time. To achieve that I'm trying to launch it with Nailgun.
I have installed Nailgun as an Ubuntu package. Then I fixed the argument bug by linking /usr/bin/ng-server
to /usr/bin/ng
. I'm starting the Nailgun-Server like this:
java -cp /usr/share/java/nailgun-0.7.1.jar -server com.martiansoftware.nailgun.NGServer
I have this simple dummy Groovy script named hello.groovy just to test the nailgun-server:
#!/usr/bin/env groovy
def sayHello() {
println("Hello Groovy!");
}
sayHello();
I compiled the file with groovyc to hello.class.
Now I want to launch that script within the Nailgun server. My naive approach to do that would be:
ng hello
ng hello.sayHello
But all I get are ClassNotFoundExceptions:
java.lang.ClassNotFoundException: hello
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at com.martiansoftware.nailgun.NGSession.run(Unknown Source)
So, what is the right way to launch my Groovy script with the Nailgun Server? I'd also appreciate some good sites/tutorials about how to use Nailgun, it's really hard to get any information how to use it...
EDIT:
I would also appreciate a complete example (including how a specific class is called with ng) for using nailgun with pure Java classes, as I could also not get ng working with any Java class.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
终于明白了。我只是不明白我必须首先将所有需要的类添加到 Nailgun 类路径中(这个问题给了我最后的提示)。
首先,将 Groovy 添加到类路径:
然后将包含 Groovy 脚本/Java 类的目录添加到类路径,在我的例子中是:
现在我可以使用 Nailgun 运行我的 Groovy 脚本,如下所示:
Finally got it. I just did not understand that I have to add all needed classes to the Nailgun classpath first (this SO question gave me the final hints).
First, add Groovy to the classpath:
Then add the directory which contains the Groovy script/Java class to the classpath, in my case it's:
Now I can run my Groovy script with Nailgun like this:
我认为 jruby.org 最近提到了这个失传已久的武器(有一天 Oracle 应该采用它,因为缓慢的冷启动对于大多数新鸟来说是一个致命弱点)
你是否将你的脚本融入到类中了?
然后在类路径上使用groovy 'ng ... hello'
我的盲目猜测(在使用rvm维护jRuby后懒得重新安装我的railgun)
I think jruby.org has the most recent reference to this long lost weapon (which some day Oracle should take up , since the sluggish cold start is an achilles heel for most new birds)
did you groovyc your script into classes?
then 'ng ... hello' with groovy on the classpath
my blind guess(too lazy to reinstall my railgun after using rvm to maintain jRuby)
如果运行的 hello 是 hello.groovy (已解释),我会感到惊讶
而不是编译下来的 hello.class
不是一个可持续的解决方案
他们应该只有一个 JSR
用于热启动客户端JVM,
使客户端模式下的JVM启动为后台守护进程,等待生成java进程,并清除Java一直以来性能不佳的所有幻想,
当然为了安全起见,生产将始终使用完整的热点
i will be surprised if the hello that is run is hello.groovy (interpreted)
and not the compiled down hello.class
not a sustainable solution
they should just have a JSR
for hot start client JVM
so that JVM in client mode starts into a background daemon, waiting to spawn a java process, and clear all the illusories of poor performance Java has always endured
of course for safety sake, production will always use the full hotspot