以下代码在控制台中执行karaf命令。这在karaf 3.0.3版本中运行良好。它在4.0.0或更高版本中失败
@Inject
CommandProcessor commandProcessor;
private class dummyCallable implements Callable{
final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
final PrintStream printStream = new PrintStream(byteArrayOutputStream);
final CommandSession commandSession = commandProcessor.createSession(System.in, printStream, System.err);
String[] commands;
dummyCallable( String[] commands){
this.commands = commands;
}
public String call() {
try {
for(String command:commands) {
System.err.println(command);
commandSession.execute(command);
}
} catch (Exception e) {
e.printStackTrace(System.err);
}
return byteArrayOutputStream.toString();
}
}
protected String executeCommands(final String ...commands) {
String response;
dummyCallable dd = new dummyCallable(commands);
ExecutorService executor = Executors.newFixedThreadPool(1);
FutureTask<String> futureTask2 = new FutureTask<String>(dd);
try {
executor.submit(futureTask2);
response = futureTask2.get();
} catch (Exception e) {
e.printStackTrace(System.err);
response = "SHELL COMMAND TIMED OUT: ";
}
return response;
}
任何人都可以为我提供一个可以使用karaf 4.0.0的代码
答案 0 :(得分:2)
在Karaf 4中,您应该向SessionFactory
注入sessionFactory.createSession(System.in, printStream, System.err)
并致电php artisan make:controller HomeController
Karaf3和Karaf4之间的方法是相同的,类和包已经改变了: