Java equivalent of fork in Java task of Ant?

穿精又带淫゛_ 提交于 2019-12-05 19:58:17

Execute another java process. By using ProcessBuilder class, for example.

http://java.sun.com/javase/6/docs/api/java/lang/ProcessBuilder.html

You can run as many worker processes as you wish. Make them having a separate main class, doing their tasks from that main class, and quiting when their task is completed.

You'll have to figure out their classpath, and the location of java binary on the system, but that's doable.

I think you can even be notified when they complete via Process.waitFor().

If you look at the ant source code, when fork is true, then it just wraps an Execute task and eventually, the code that gets called is

Runtime.getRuntime().exec(cmd, env);

Downloading and having a look at the source code for org.apache.tools.ant.taskdefs.Java and org.apache.tools.ant.taskdefs.Execute will give you some great pointers in finding the location of the executable to run in a platform independent way, etc.

I think you can directly use the Ant API...Ant can be directly used in a Java class. The Javadoc is available in their binary distribution.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!