1

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.

leo
  • 3,677
  • 7
  • 34
  • 46

1 Answers1

1

I'm executing it differently, see my question - Doclet: firstSentence is null

I'd say (without a testing), that your parameters should be something like:

    String[] params = new String[] {
            "-doclet", "com.sun.tools.doclets.standard.Standard",
            "-sourcepath", "C:\\Program Files (x86)\\Java\\jdk1.7.0_51\\src\\",
            "java.util"
    };
    com.sun.tools.javadoc.Main.execute(params);
Community
  • 1
  • 1
Betlista
  • 10,327
  • 13
  • 69
  • 110