File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Ant, Maven and Other Build Tools and the fly likes Forking Problems Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Forking Problems" Watch "Forking Problems" New topic

Forking Problems

Nathaniel Stoddard
Ranch Hand

Joined: May 29, 2003
Posts: 1258
Sorry for the subject pun.
Here's what's going on ... I'm trying to run a java task inside one of my targets, and I have the fork set to true (it's a jar), but the stupid thing won't fork.
Is there some issue regarding this?

Tony Yan
Ranch Hand

Joined: Apr 10, 2002
Posts: 170
Please be more specific. What do you mean by not forking?

Tony Yan<br /> <br />IBM Certified Developer XML and Related Technology<br />Sun Certified Web Component Developer For J2EE Platform<br />Sun Certified Programmer For Java 2 Platform
Nathaniel Stoddard
Ranch Hand

Joined: May 29, 2003
Posts: 1258
Well, basically, it's not forking!
My build script blocks until my java task finishes (program is exited) even though I have forking enabled.
Tony Yan
Ranch Hand

Joined: Apr 10, 2002
Posts: 170
I tried some bogus ant script with forking enabled. Yes, i got what you got too. It is still a single threaded behavior. I wonder if this is normal or a bug. It is said that forking starts a new java vm to run javac. Does that mean it will be on its own Thread?
Any one got ideas?
Frank Carver

Joined: Jan 07, 1999
Posts: 6920
As far as I understand, "fork" is intended to run a task in its own VM mainly so that if the task crashes or exits the VM, it won't crash the whole build. With this in mind, the sequencing of the build process still requires that prerequisite tasks are preformed before dependent ones, so the build has to wait for the "forked" tasks to complete.
I'm not sure the Ant build specification would even make sense if some tasks could run asynchronously. When would it make sense to run a dependent task - as soon as the asynchronous task has started? Wait for five seconds and hope it has finished? Spin checking modification times until some external resource has been updated? Something else?
On the other hand, if you really need something like this, there are plenty of examples of custom tasks which do start asynchronous processing - all the ones which start a server, for example. They don't usually use "fork", though, just run a small in-VM task which executes an external OS-level program as a background process, then immediately returns to the calling build script.

Read about me at ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Tony Yan
Ranch Hand

Joined: Apr 10, 2002
Posts: 170
Well said. Thanks, Frank.
Stanley Smith

Joined: Sep 05, 2002
Posts: 2
This is a sample of how I try to javac in 1.1.8 with 1.4 as my standard VM for ANT (through IDEA). If anyone knows how to ensure that the VM for the java task is 1.1.8 please share, I am having trouble getting the java command to run in 1.1.8. The help pages on ANT's java task say to set fork="true" to run in a different VM than the main ANT VM. But can't figure out to saw what VM that is.

<target name="robscompile" depends="init">
<javac srcdir="${src}"
I agree. Here's the link:
subject: Forking Problems
It's not a secret anymore!