コマンドラインを呼び出すタスクです。
コマンドラインを呼び出すタスクを作成するのは簡単です。
ここでは簡単な例を紹介します。
いきなりwindows限定で申し訳ないが、
エクスプローラーを表示するタスクです。
extends Taskして、
public void execute()
中でruntimeを実行するだけです。
package org.jpn.xucker.ant;
import java.io.IOException;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
public class ExplorerTask extends Task{
private String path;
public void execute() throws BuildException {
Runtime runtime=Runtime.getRuntime();
String args[]={"explorer.exe",path};
try {
Process process=runtime.exec(args);
} catch (IOException e) {
// TODO 自動生成された catch ブロック
e.printStackTrace();
}
}
/**
* @return
*/
public String getPath() {
return path;
}
/**
* @param string
*/
public void setPath(String string) {
path = string;
}
}
値の受け渡しは基本的には、beanのメカニズムを使いますので、
単純に、変数名をいいです。
以下のようにしてこのタスクを使用することができます。
<taskdef name="explorer" class="org.jpn.xucker.ant.ExplorerTask"/> <explorer path="http://www.xucker.jpn.org"/>
