views:

724

answers:

5

I'm building jars where I want to package them without sources but I would like the javadoc to come up for developers in eclipse.

A: 

Javadocs are part of the source code, as any compiled class won't contain any comment - Javadocs are comments.

In other words, you can't.

Seb
But javadoc produces HTML which I can manually point eclipse to either as a folder or a jar. I just want to be able to include this in my distributed jars such that eclipse finds it.
Tom
That's right, but you won't be able to put that _inside_ your JAR. Anyway, all solutions working the way you describe provide an external source zip file that contains _both_ sources and javadoc. If you want, you could strip method sources and create an empty shell that will serve as javadoc sources.
Seb
+1  A: 

The users of your JAR can associate a Javadoc location (URL, file or path inside an archive) to it in the Java Build Path properties of the Java project, where the JAR is used.
I'm not sure how well this would work with the Javadoc in the same JAR as the binaries (never seen that before), but in theory it should work.

Zsolt Török
+1  A: 

Apache Ant javadoc task will produce API html. Normally you would then distribute this as a zip file along with your jars.

Ben Hammond
A: 

What is your build process? The Maven release process actually generates 3 jars, one containing the compiled classes, one with sources and one with javadocs. You should be able to customize the POM to prevent distribution of the source jar, and anyone using Maven to manage dependencies will automatically get the javadoc if they declare a dependency on your jar (and have javadoc downloading turned on in the eclipse maven plugin).

Jherico
Alas we're using ant rather than maven :o(
Tom
You can use the maven build tasks to generate the javadoc and or source jars, even from Ant. Since you're using ant for building and presumably dependency management, you'd only need a minimal pom for maven to work, specifying the source directory from which to generate the javadoc
Jherico
This is what I've done in the end, well sort of I'm building the src and doc jars through ant not maven.
Tom
A: 

JIDE have a tool (costs $25) that will run over your source code and strip out all the method bodies, leaving the javadoc in, and produces a zip file. You can then distribute this zip as a source zip, and your IDE will be able to read the javadocs, but of course all your logic has been removed so you can retain your closed-sourceness. Any private members and methods are not included in the zip file.

It also has the added bonus of retaining method parameter names for intellisense, so the following method

public void foo( String text, Integer index ) {
}

will show foo( String text, Integer index ) when you auto-complete, instead of foo( String arg1, Integer arg2 ) so you can hint what the parameters should be.

banjollity