Java: How to compile and run in Windows command-line

Let's say we want to test GSON library in Windows command-line. Here is what to do step-by-step
  1. Install Git for Windows and "xargs"
  2. cd c:\temp
  3. git clone https://github.com/google/gson/tree/master/gson.git
  4. cd c:\temp\gson\gson\src\main
  5. mkdir ..\build
  6. dir /b /s *.java | xargs javac -d ..\build
  7. cd ..\
  8. jar cf ..\gson.jar -C build .
Now gson.jar is created.

Next, create a Java source file with the following contents:

import com.google.gson.Gson;

public class SimpleTest {

    static class TestObj {
        int value1 = 1;
        String value2 = "abc";
    }

    public static void main(String[] args) {
        Gson gson = new Gson();

        TestObj[] objs = new TestObj[3];
        for (int i = 0; i < objs.length; ++i)
            objs[i] = new TestObj();

        List objs2 = new ArrayList();
        objs2.add(objs[0]);
        objs2.add(objs[1]);
        objs2.add(objs[2]);

        System.out.println(gson.toJson(objs));
        System.out.println(gson.toJson(objs2));
    }
}
Save it to c:\temp\SimpleTest.java

Then compile it:

And run it If it is to be run in Linux, replace ; (before gson.jar) by :