Theoretically it should be possible to run the javadoc generation process from a Java programm itself (as described here http://docs.oracle.com/javase/7/docs/technotes/guides/javadoc/standard-doclet.html#runningprogrammatically). I took the programm from here and changed it slightly as seen bellow. However when I call the doTest method from the mainmethod of my class I allways get the return code "1" from the execute function which results in the Error.
static void doTest() {
ByteArrayOutputStream redirectedOutput = new ByteArrayOutputStream();
PrintStream originalOutput = System.out;
// redirect System.out to a buffer
System.setOut(new PrintStream(redirectedOutput));
PrintWriter sink = new PrintWriter(new ByteArrayOutputStream());
// execute javadoc
int result = com.sun.tools.javadoc.Main
.execute(
"javadoc", sink, sink, sink,
"com.sun.tools.doclets.standard.Standard",
new String[] {
"-sourcepath",
"\"C:\\Program Files (x86)\\Java\\jdk1.7.0_51\\src\\\"",
"java.util" });
// test whether javadoc did any output to System.out
if (redirectedOutput.toByteArray().length > 0) {
originalOutput
.println("Test failed; here's what javadoc wrote on its standard output:");
originalOutput.println(redirectedOutput.toString());
throw new Error("javadoc output wasn\'t properly redirected");
} else if (result != 0) {
throw new Error("javadoc run failed " + result);
} else {
originalOutput.println("OK, good");
}
}
I can generate the javadoc with the following line:
C:\Program Files (x86)\Java\jdk1.7.0_51\bin>javadoc -sourcepath ..\src\ -d "C:\Users\leo\Eigene Dateien\javadoc" java.util
My enviroment is Windows with JDK 1.7.0_51.