24

When I have to generate javadocs for a new, unfamiliar project, I find that I spend a long time trying to simply write the correct command, specifying all the packages, all the source trees, etc. It's time-consuming and error-prone: I'm probably missing some source.

So let's say I have a directory myproj, and underneath it there are a few packages (and various other resources and stuff), and under those package directories there are eventually some src/ directories, and then lots of my/awesome/java/project/package type structures.

Is there a single command that will always recurse over EVERYTHING and generate ALL javadocs in one output location? I don't care how long it takes. Something brain-dead like javadoc -d doc -sourcepath . -subpackages * would be great. Failing that, what's the easiest way to generate all javadocs, no matter what the directory structure is?

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
Steve Bennett
  • 114,604
  • 39
  • 168
  • 219

2 Answers2

38

Use find to find all Java source files and then send them to javadoc:

find . -type f -name "*.java" | xargs javadoc -d outputdir 
dogbane
  • 266,786
  • 75
  • 396
  • 414
22

On Windows you can do it like this:

Generate file list:

dir /s /b *.java > file.lst

Generate javadoc:

javadoc -d outputdir @file.lst
stian
  • 2,874
  • 3
  • 24
  • 38
  • 1
    Excellent, native, functionally equivalent alternative to the above. – Steve Bennett Feb 10 '11 at 04:24
  • Is there a way to get Javadoc to generate the index list of all packages after using this method. with the simple "javadoc -d [dir] @[file]" method there is no index. – JasonRobinson Aug 30 '17 at 21:54
  • Any idea how to get this to work if some of the paths have spaces in the name? – Ryan Lundy Jun 21 '19 at 06:24
  • @RyanLundy Encapsulate all of them inside a single/double quote. For example: dir "/s dir" "/b dir" *.java > file.lst ; javadoc -d "outpit dir" "@file.lst" – harveyhans Dec 30 '22 at 19:55