Ant, java.io.IOException: CreateProcess and That Darn Command Prompt
I'm usually slow to blame someone else for every bug or feature that trips me up,
but some things really get to me. Did you know
that the Command Prompt (Cmd.exe) limits the length of its input? On
Windows XP it's 8,191 characters, and on Windows 2000 it's 2,047. That 2,047-character limit has burned me
at least twice.
The first time was with our application server, where we set
a ridiculously long classpath. It caught me out again yesterday.
This time, figuring out that it was the input length limit
cost me a fair bit of time and frayed a few nerves.
Enter Javadoc
Ant is quite the wizard. One of its
spells is the Javadoc task,
which generates documentation from source files, assuming you write it in the first place.
Yesterday I urgently needed to generate the API docs.
Unfortunately, every attempt to run the task on Windows 2000 ended in BUILD FAILED,
with the messagefailed:java.io.IOException: CreateProcess:"and a very long
stack trace that started withjava.lang.Win32Process.create(Native Method).
Of course, the task ran fine on my Windows XP machine. I tried
different versions of Ant and Java, but nothing helped.
This morning I decided to get to the bottom of it. I turned to my old friend
Google, and a few queries showed that, as usual, plenty of
other poor souls had hit the same problem. Ant calls javadoc.exe
to generate the documentation and passes its arguments
on the command line. No wonder
the command can easily exceed 2,047 characters.
Luckily, Google also turned up a fix. The Javadoc task supports a magic attribute
calleduseexternalfile.
indicates whether the sourcefile name specified in srcfiles or as nested source elements should be written to a temporary file to make the command line shorter. Also applies to the package names specified via the packagenames attribute or nested package elements. (yes | no). Default is no.
I owe the fix to these three discussions, 1, 2 and 3.
Related articles
Related CZ Podcast episodes
- #3 · Java 6 SE, Vývoj webových aplikací
Dagi and Filemon discuss Java 6 and web application frameworks. · Czech audio
- #1 · Vývojová prostředí v Javě
The first CZ Podcast episode looks at Java development environments. · Czech audio