Edit: I read the similar Question, but its not working here. I have to check assignments for students. To the assignments have the same name(Ex2.java),they are in different directories. I want my test file to run all the assignments without having to go through each assignment separately.
I tried to compile and run function from another class. But there is no main there.
Lets say that I have this class without main:
public class A {
public static int num(int x) {
return x;
}
}
The main class:
public class B {
public static void main(String[] args) throws Exception {
Process p = Runtime.getRuntime().exec("javac A.java");
Process p2 = Runtime.getRuntime().exec("java A");
}
}
Now I want that class B compile and run class A. Try to write something like this in class B:
A.num(x);