Skip to main content

Running Javadoc Programmatically

3 replies [Last post]
frodero
Offline
Joined: 2008-01-30
Points: 0

Hi all,

I want to dynamically get javadoc information from the source code of a class. I use sample code from java.sun.com which works in a simple HelloWorld-like application but it does not work into a more complex application. The code used to launch javadoc from my application is:

String[] javadocargs = { "-private", fullpath + filename + ".java"};
System.out.println("TRACE1");
com.sun.tools.javadoc.Main.execute("TestEngine","testool.TestEngine.Report.TestToolDoclet", javadocargs);
System.out.println("TRACE2");

In the console I can see TRACE1 but not TRACE2...the execute method of com.sun.tools.javadoc.Main class seems to be a black hole!!! I surrounded the invocation with a try/catch and no Exception is thrown... (the application, which is composed of various threads seems to continue working normally but the javadoc is not generated).

The most curious thing is that if I debug my application with Eclipse, putting a breakpoint in the invocation and stepping over....it works and it generates the javadoc!!! What Eclipse does that the application in a stand-alone execution way does not? (If it was a classpath problem I will get the corresponding Exception but it is not the case....in addition I added the lib/tools.jar from JDK to the CLASSPATH when launching the application JAR).

Quick comments will be strongly appreciated :-)

By the moment, I will try to launch the javadoc invocation through a Runtime.exe call but I think that the best practice is to use javadoc programmatically, isn't it?

Thanking you all in advanced!

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
ssdfaceopen
Offline
Joined: 2011-04-02
Points: 0

frodero wrote:
Hi all,

I want to dynamically get javadoc information from the source code of a class. I use sample code from java.sun.com which works in a simple HelloWorld-like application but it does not work into a more complex application. The code used to launch javadoc from my application is:

String[] javadocargs = { "-private", fullpath + filename + ".java"};
System.out.println("TRACE1");
com.sun.tools.javadoc.Main.execute("TestEngine","testool.TestEngine.Report.TestToolDoclet", javadocargs);
System.out.println("TRACE2");

In the console I can see TRACE1 but not TRACE2...the execute method of com.sun.tools.javadoc.Main class seems to be a black hole!!! I surrounded the invocation with a try/catch and no Exception is thrown... (the application, which is composed of various threads seems to continue working normally but the javadoc is not generated).

The most curious thing is that if I debug my application with Eclipse, putting a breakpoint in the invocation and stepping over....it works and it generates the javadoc!!! What Eclipse does that the application in a stand-alone execution way does not? (If it was a classpath problem I will get the corresponding Exception but it is not the case....in addition I added the lib/tools.jar from JDK to the CLASSPATH when launching the application JAR).

Quick comments will be strongly appreciated :-)

By the moment, I will try to launch the javadoc invocation through a Runtime.exe call but I think that the best practice is to use javadoc programmatically, isn't it?

Thanking you all in advanced!

frodero
Offline
Joined: 2008-01-30
Points: 0

Hi again,

As I announced at the end of the post, the Runtime.exec test calling for the javadoc command line tool results in a successful execution and therefore, generation of javadoc in a custom format to a specific file.....BUT, it continues being a "black-hole" which causes unexpected behaviour of my application since the code after the call to the system is not executed...
If this process is repeated more than one time it always happens the same....I can execute the system command whenever I want (with a successful execution) but the code after is not executed!

Any idea?

kithouna
Offline
Joined: 2011-03-28
Points: 0

i know... the question was asked loooooong time ago. but anyway:

the reason you can't see TRACE2 is, that the Main.execute(...)-Method calls the System.exit()-Method when it is done. thus, your programm/application terminates as well.

greetz