1
我有以下的Java代碼,我要轉換爲常規:Groovy中不執行Java的方法(簽名包括仿製藥)
String containerId = "545cdc81a969";
ExecCreateCmdResponse execCreateCmdResponse = dockerClient
.execCreateCmd(containerId)
.withAttachStdout(true)
.withCmd("sh", "-c", "sleep 5 && exit 5")
.exec();
ExecStartResultCallback execStartCmd =
dockerClient.execStartCmd(execCreateCmdResponse.getId())
.exec(new ExecStartResultCallback(System.out, System.err))
.awaitCompletion();
我現在的版本在Groovy是這樣的:
String id = "545cdc81a969";
def execCreateCmdResponse = dockerClient
.execCreateCmd(id)
.withAttachStdout(true)
.withCmd('sh','-c','sleep 5 && exit 5')
.exec()
dockerClient.execStartCmd(execCreateCmdResponse.getId())
.withDetach(false)
.exec(new ExecStartResultCallback(System.out, System.err))
.awaitCompletion()
我的問題是,我得到以下錯誤,當我嘗試運行Groovy代碼:
* What went wrong:
Execution failed for task ':werner'.
> No signature of method: com.github.dockerjava.core.command.ExecStartCmdImpl.exec() is applicable for argument types: (com.github.dockerjava.core.command.ExecStartResultCallback) values: [[email protected]155]
Possible solutions: exec(com.github.dockerjava.api.async.ResultCallback), exec(com.github.dockerjava.api.async.ResultCallback), every(), grep(), every(groovy.lang.Closure), grep(java.lang.Object)
的Java的exec-方法有簽名:
public <T extends ResultCallback<Frame>> T exec(T resultCallback);
我試着投 「新ExecStartResultCallback(的System.out,System.err的)」 到 「ResultCallback」,但沒有奏效。
有沒有辦法強制Groovy將實例作爲ResultCallback-Instance處理,以便調用正確的方法?
問候, marbon
請先添加'stacktrace'。那麼只有我們能夠幫助你解決@marbon。 'ExecStartResultCallback'類是'ResultCallbackTemplate'類,不是類型爲'ResultCallback'的類,如這裏所述>> https://github.com/docker-java/docker-java/blob/master/src/main/java/ com/github/dockerjava/core/command/ExecStartResultCallback.java –
@VikrantKashyap但是'ResultCallbackTemplate'是一個'ResultCallback',因爲它在這裏說:https://github.com/docker-java/docker-java/blob/master/的src /主/ JAVA/COM/github上/ dockerjava /核心/異步/ ResultCallbackTemplate.java –