private <T extends OptionParsingCommand> Future<T> submitCommand(final T command, String... args) { clearUrlHandler(); final String[] sources = getSources(args); return Executors.newSingleThreadExecutor().submit(new Callable<T>() { @Override public T call() throws Exception { ClassLoader loader = Thread.currentThread().getContextClassLoader(); System.setProperty("server.port", String.valueOf(CliTester.this.port)); try { command.run(sources); return command; } finally { System.clearProperty("server.port"); Thread.currentThread().setContextClassLoader(loader); } } }); }