Home > eclipse, java > Running javadoc Ant task from Eclipse

Running javadoc Ant task from Eclipse

December 9th, 2008 Leave a comment Go to comments

All things being equal, I like projects that build out-of-the-box. That is, given a clean checkout from revision control, a project should just build without requiring too much customization: setting environment variables, installing third party software, modifying the system path. I’m especially sensitive to this at the moment because I’ve just finished up five days (actually maybe 30 hours all together) getting one particularly horrible system to build.

Along these lines, I added a javadoc task to an Ant build script today and tried running it from Eclipse. Just for the record, that procedure is as follows:

  • Open build.xml
  • Right-click the task in the Outline View
  • Select Run As->Ant build.

Interestingly enough, this failed with the following error:

build.xml:208: Javadoc failed: java.io.IOException: Cannot run program
"javadoc.exe": CreateProcess error=2, The system cannot find the file

A quick Google search reveals several suggestions that the solution is to make sure that javadoc.exe is on the system path.  First, it’s a little ridiculous that Ant can’t find javadoc from JAVA_HOME when it clearly uses the same mechanism to track down javac. Oh well. Bygones. Second, returning to the idea of builds that “just work”, I don’t want to modify my system path. What if I have several JDKs installed, used with several different projects simultaneously?

So, how do we get javadoc onto the system path without modifying it? Simple, modify the path in Eclipse. This time, run the Ant task with the following procedure:

  • Open build.xml
  • Right-click the task in the Outline View
  • Select Run As->Ant Build …

That elipsis at the end is important. This will bring up the Eclipse launch configuration dialog. Give your new launch configuration a name, like “Build <Project Name>” or something and switch to the Environment tab. Here you can specify the environment for Ant. But we don’t want to kill the whole system path, just prepend the location of javadoc.exe to it. So click New… and enter Path for the name and the following for the value:


This prepends JAVA_HOME/bin to the current system path. Now click Run and everything should work fine. Yay.

Now, when someone else checks out the project you don’t want them to have to go through the same hassle. It’s still a hassle, just inside Eclipse instead somewhere else on the machine. The solution to this problem is to save the launch configuration!  Return to the launch configuration screen and open the Common tab. There you can select to save the configuration as a shared file. I usually save it in tools/launches. The resulting file will have a .launch extension. Commit the launch file to version control. Now anyone who checks out the project will have a properly configured launch configuration to build the project. No fuss, no muss.

Also note that this is a much more general purpose solution. It applies to any launch configuration where you need to modify the path, or set any kind of environment variables.

Possible Issues

There are a few potential issues I can think of:

  • That semi-colon in the path string may not work on non-Windows systems. I’m not sure if Eclipse is smart enough to fix that.
  • In the past, I’ve had trouble with the case of environment variables and Ant.

Also, I believe that an alternate solution to this problem is to register the JDK in Eclipse. This is ok, but it’s nice to not require it.

Categories: eclipse, java Tags: , ,
  1. April 8th, 2010 at 05:45 | #1

    Thanks, had similar problem, trick with Environment variable helped me with my ant gen-javadoc task on eclipse_3_5, indeed this is “little ridiculous”.

  2. August 16th, 2010 at 06:42 | #2

    Thanks for the tips! By the way, you can just drop javadoc.exe in your windows/system32 folder. This works from eclipse and the command line!

  3. Sergio
    September 30th, 2010 at 05:59 | #3

    Thank you for your help, it works for me!

  4. October 28th, 2010 at 05:47 | #4

    The same problem you may have in eclipse, if you are using a JRE (not a JDK) as JRE in eclipse…

  5. October 30th, 2010 at 04:41 | #5

    You you should edit the page name Along Came Betty » Running javadoc Ant task from Eclipse to something more generic for your subject you create. I loved the blog post still.

  6. David
    November 18th, 2010 at 07:16 | #6

    Únicamente tienes que poner bien la variable de entorno PATH :-)Esta tiene que apuntar a la carpeta bin del JDK

  7. nhefr
    December 1st, 2010 at 06:06 | #7

    Works perfect, Thanks!

  8. Megan
    December 13th, 2010 at 18:13 | #8

    You just saved my life — thank you SO much for this article.

  9. tom
    March 15th, 2011 at 10:21 | #9

    thank you :)

  10. cheenujunk
    June 9th, 2011 at 14:20 | #10

    Its really amazing. A small stuff that is really necessary… good work.

  11. June 9th, 2011 at 15:18 | #11

    No problem. A big chunk of my traffic comes from searches like “eclipse javadoc failed: java.io.ioexception”, which is kind of depressing, actually :)

  12. bgausden
    July 28th, 2011 at 03:38 | #12

    Never occurred to me that the exec_dir wouldn’t be on the PATH. Was scratching my head over this one until I read this post…

  13. Desmond
    August 4th, 2011 at 12:05 | #13

    Thanks for the blog posting. I had the same problem as you. I found a better resolution.
    Open build.xml
    Right-click the task in the Outline View
    Select Run As->Ant Build…
    Select JRE tab
    Change Runtime JRE from a JRE to a JDK.
    Voilà! It works.

  14. so
    August 9th, 2011 at 02:58 | #14

    thanks..it helped a lot…:)

  15. Janet
    August 29th, 2011 at 12:11 | #15

    I LOVE ALONG CAME BETTY!!! Thank you!

  16. Anand Naphade
    December 17th, 2011 at 01:33 | #16

    thank you… this solution works perfectly……………….

  17. Ann
    March 27th, 2012 at 07:01 | #17

    Thanks.. This solved my problem.

  18. vivek
    October 5th, 2012 at 12:13 | #18

    Adding \bin in path also worked in my case.

  19. BigDaddy
    October 11th, 2012 at 16:50 | #19

    your solution is better than this article.Thanks Dude

  20. huschi
    March 21st, 2013 at 04:53 | #20

    imho best solution. Thanks!

  21. sleepy
    March 29th, 2013 at 10:55 | #21

    Awesome tips. Thanks :-)

  22. Lars
    July 8th, 2015 at 10:10 | #22

    A timeless hint!! A pity that you’re now blogging anymore ’bout dev stuff, as it seems :/

    Thanks for this valuable information.

  23. Robert Sullivan
    February 29th, 2016 at 19:09 | #23

    Yup, this was the trick, thanks! I did not realize Javadoc used executed using an entirely separate version of the JDK, but your post clued me in to the solution – setting the JAVA_HOME to (in my case) Java 1.8 in the Windows System Properties Environment Variables. Go figure. Nowhere could I find in Stackoverflow, Ant, or Eclipse, that, while you ran an Ant script and can set the target compiler (as some commentators have mentioned), that is NOT the case for the Javadoc command. This note in the Ant documentation should have clued me in too: ”

    Thanks again!!

  24. Robert Sullivan
    February 29th, 2016 at 19:14 | #24

    Oops, note didn’t get added previously perhaps because I cut and past the xml version I had added as a comment. Here it is, and the link to the source:

    NOTE: since javadoc calls System.exit(), javadoc cannot be run inside the same VM as Apache Ant without
    breaking functionality. For this reason, this task always forks the VM. This overhead is not significant since
    javadoc is normally a heavy application and will be called infrequently.


  25. albina elvira
    September 6th, 2016 at 05:34 | #25

    The path you entered, is too long. Enter a shorter path
    File Name could not be found. Check the spelling of the filename,
    and verify that the file location is correct

  1. September 29th, 2011 at 15:36 | #1