Reputation: 21248
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.
Upvotes: 3
Views: 1893
Reputation: 21248
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:
ng ng-cp /usr/share/java/groovy-all.jar
Then add the directory which contains the Groovy script/Java class to the classpath, in my case it's:
ng ng-cp /home/$USER/tools/groovy
Now I can run my Groovy script with Nailgun like this:
ng hello
Upvotes: 5
Reputation: 26
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
Upvotes: 0
Reputation: 175
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)
Upvotes: 0