Possible answer 1:
The Google closure compiler does accept multiple input files with a syntax like this:
java -jar compiler.jar --js=in1.js --js=in2.js ... --js_output_file=out.js
This will produce only one output file that is the combination of all of the inputs. But this might not be what you want if you're trying to compile each file separately.
Possible answer 2:
It would not be hard to write a small wrapper script (using bash
, python
, or your favorite scripting language) that accepts pairs of parameters, e.g.
wrapper.sh in1.js out1.js in2.js out2.js ...
The code in wrapper.sh
could loop over the (pairs of) parameters and call java -jar --js=xxx --js_output_file=yyy
repeatedly, waiting for each to complete before beginning the next. This would have the benefit of not starting each process in parallel, so at least you wouldn't have (potentially) many JVMs running at the same time. Though you do have some inefficiency in having to restart the JVM for each run.
Possible answer 3:
If you really want just one JVM, then there is no way to do what you ask without writing a little bit of Java code (as far as I know). If you are familiar with Java, you could copy the source code of CommandLineRunner.java and modify it to suit your needs.
Or perhaps even easier, just write a small Java class whose main
function simply invokes the CommandLineRunner
main any number of times, passing in appropriate parameters to simulate a normal command line invocation. Here's something quick and dirty that would do the trick (hat tip to VonC)
import com.google.javascript.jscomp.CommandLineRunner;
import java.security.Permission;
public class MyRunner {
public static void main(String [] args) {
// Necessary since the closure compiler calls System.exit(...).
System.setSecurityManager(new NoExitSecurityManager());
for (int i=0; i<args.length; i+=2) {
System.out.println("Compiling " + args[i] + " into " + args[i+1] + "...");
try {
CommandLineRunner.main(new String[] {
"--js=" + args[i],
"--js_output_file=" + args[i+1]
});
}
catch (ExitException ee) {
System.out.println("Finished with status: " + ee.getStatus());
}
}
}
private static class ExitException extends SecurityException {
private int status;
public ExitException(int status) { this.status = status; }
public int getStatus() { return status; }
}
private static class NoExitSecurityManager extends SecurityManager {
public void checkPermission(Permission p) { }
public void checkPermission(Permission p, Object context) { }
public void checkExit(int status) { throw new ExitException(status); }
}
}
Compile it with with something like this:
javac -classpath compiler.jar MyRunner.java
Run it with something like this:
java -classpath .:compiler.jar MyRunner in1.js out1.js in2.js out2.js ...
And see output like this:
Compiling in1.js into out1.js...
Finished with status: 0
Compiling in2.js into out2.js...
Finished with status: 0