Home > Enterprise >  How to include Javadoc in a library JAR?
How to include Javadoc in a library JAR?

Time:02-04

I'm currently trying to write my first own library. It's just for testing, I want to find out how libraries are written, compiled, distributed and used in order to prepare for some upcoming personal projects.

Yet, what really causes me to wonder, is why exactly my Javadoc isn't compiled with the Library. I know that comments and annotations are not compiled, but for example the JDK (which is basically a huge library) comes with a working doc as well.

I've tried to compile a JAR (libraries aree normally JARs, right?) from not the compile output, but the sources (so I had a JAR of .java files), but this failed to be included in IntelliJ. I could add it as an external library, but neither did it show up in my explorer, not could I import or use any of my classes.

I know there must be a mistake somewhere here, all libraries I've ver used, whether it was Java, C# or whatever else always came with a working documentation (IntelliJ shold show that on mouse hover), and I'd like to know how to correctly build a library that I can share with a team partner, so he just needs to download it, add it as a library in IntelliJ and has all the functionality, but also the documentation.

Thanks to everyone in advance!

CodePudding user response:

Because it isn't needed, and would bloat the file size of the executable. If you have a library in C or C , the documentation may be bundled in a zip file, but you won't find it in the compiled .so or .dll. One just holds the binary and resources needed for the project. The .jar is equivalent of that- it's the compiled output. Documentation is hosted/downloaded separately.

When you download the JDK, you're not just downloading a giant .jar. It includes other things, like documentation in the download.

CodePudding user response:

Alright, if everyone ever has this probelm again, here's a complete tutorial:

As @Gabe Sechan already said, the Doc is not compiled into the JAR for some valid reasons. Instead, I recommend you to add the following to your JAR:

  • module compilation output
  • content of "src" directory / alternatively: module sources

Build --> Artifacts --> All Artifacts.

Now, if you add your library JAR into a project, it will show "Classes" and "Sources" in the right tab, as IntelliJ automatically recognizes you've bundled both into the JAR.

Now, IntelliJ should show your documentation, as it lives within the source files.

If, for some reason, IntelliJ switches from its "fancy" documentation popup to unformatted plain text, proceed as follows:

Navigate to File -> Settings -> Advanced Settings, and in the 5th block, where it says "Documentation Components", just tick everything you find. That's gonna fix it.

Thanks to Gabe Sechan again, your answer helped me to understand what won't work, and finally I've found a way to make it work myself.

  • Related