-fork
<?xml version="1.0" encoding="ISO-8859-1"?> <project default="test" basedir="."> <target name="java"> <java classname="dev.Main2" fork="true"> <classpath> <pathelement path="context/WEB-INF/classes"/> <fileset dir="context/WEB-INF/lib"/> </classpath> </java> </target> </project>
というように、fork="true"にしたら動作!ふむ。しかしMainに変えたら以下のエラー。
Exception in thread "main" java.lang.NoClassDefFoundError: javax.servlet.http.HttpServletRequest
ちっ。コンソールアプリだが要求されるモノは仕方ない、Servlet.jarを追加するか。
public class ParserTask extends Task { private CommandlineJava _commandline = new CommandlineJava(); public Path createClasspath() { return _commandline.createClasspath(getProject()).createPath(); } @Override public void execute() throws BuildException { _commandline.setClassname(Main.class.getName()); Execute exe = new Execute(); exe.setAntRun(getProject()); exe.setWorkingDirectory(getProject().getBaseDir()); exe.setCommandline(_commandline.getCommandline()); try { exe.execute(); } catch (IOException e) { throw new BuildException(e, getLocation()); } } }
これで動作!やれやれ。