facebookarchive/nailgun

Run nailgun without classpath as code comes on the fly

Opened this issue · 1 comments

Hi Nailgun Team
How to run the java codes without adding them to the classpath?

I have two HelloWorld.java files.

1/HelloWorld.java

public class HelloWorld {
  public static void main(String[] args) {
    System.out.println("Hello, world! 1");
  }
}

2/HelloWorld.java

public class HelloWorld {
  public static void main(String[] args) {
    System.out.println("Hello, world! 2");
  }
}

I compiled both of them separately.
javac 1/HelloWorld.java
javac 2/HelloWorld.java

I add in classpath individually and run HelloWorld individually. But the second one doesn't reflect.

ng ng-cp 1/
ng HelloWorld
Hello, world! 1

ng ng-cp 2/
ng HelloWorld
Hello, world! 1

Similarly, I get 100s of students' submissions of java code for a shared problem, all of which have the same class name and no package name.

How can I run those separately using nailgun?

angwe commented

You are using the wrong tool. Nailgun works when you want to run the same java process (including libraries/classes/packages) many times over with different parameters without incurring JVM startup overhead. By its nature, it is keeping one set of libraries/classes/packages the entire time the server is running. I suspect that when you tried to run the second instance of nailgun with a different classpath, it crashed behind the scenes because the port wasn't available. Unless you kill the server with the old classpath and start a new one with the new classpath, asking for the same alias/class each time will keep giving you the first one you loaded.

java ... -cp /path/to/nailgun-server.jar:/path/to/1/ com.facebook.nailgun.NGServer

That's starting your NGServer.

ng HelloWorld

That invokes the "HelloWorld" class from the nailgun server and you get "Hello, world! 1"

java ... -cp /path/to/nailgun-server.jar:/path/to/2/ com.facebook.nailgun.NGServer

That fails to start because there's already a nailgun server running with your default settings and it can't have the TCP port.

ng HelloWorld

That invokes the "HelloWorld" class from the already running nailgun server and you get "Hello, world! 1"

I think that if you were to write a class that uses ClassLoader to pull in each student's code, run the test against it, and output results, you could load that into nailgun and then only have to automate the process of invoking that against each student's class.

java ... -cp /path/to/nailgun-server.jar:/path/to/MyClassLoaderAndTestSuite.jar com.facebook.nailgun.NGServer

ng MyClassLoaderAndTestSuite Student1/HelloWorld.class
ng MyClassLoaderAndTestSuite Student2/HelloWorld.class
...
ng MyClassLoaderAndTestSuite StudentN/HelloWorld.class

I cannot make any recommendations on how to do so, as I am not a Java programmer.