22

Looking at Google gson 2.8.5 , I see several jars are distributed here https://repo1.maven.org/maven2/com/google/code/gson/gson/2.8.5/

  • gson-2.8.5-javadoc.jar
  • gson-2.8.5-sources.jar
  • gson-2.8.5.jar

By reading other posts, I understand that sources.jar contains source code, but jar contains the compiled class files.

  1. Does this mean that, given the sources.jar, I can generate the jar myself? What is the general relationship between these three jars?
  2. What is javadoc.jar? Does it only contain documentation, or source code / compiled classes too?
Kevin Maxwell
  • 339
  • 2
  • 3
  • 3
    with source code you can debug, with javadoc you can... well... read the documentation from your IDE – Federico klez Culloca Jan 25 '19 at 19:09
  • 1
    As a side note, if you're curious open them with a program that can read ZIP files and see what's inside. – Federico klez Culloca Jan 25 '19 at 19:10
  • 1
    Both files are intended for IDEs, where the `sources` files allows you to step through the code in a debugger, so you can actually see the source code you're stepping through, and the `javadoc` file allows the IDE to show you the javadoc of the classes and methods, while you're editing your code making calls to the classes defined in the jar file. – Andreas Jan 25 '19 at 19:12
  • 4
    There is no reason to downvote this post. The question is clear and understandable, so it is possible to provide an answer. The fact that you expect everyone to know a particular thing is no reason to downvote! – Tobb Jan 25 '19 at 19:13
  • Partial duplicate of [What is a sources JAR?](https://stackoverflow.com/q/30686312/5221149) – Andreas Jan 25 '19 at 19:17
  • @OP Welcome to stackoverflow. Please make sure you google before posting. – Tobb Jan 25 '19 at 19:18
  • @FedericoklezCulloca Thank you, very helpful advice! I ran `jar xf gson-2.8.5.jar` and am now inspecting the content of the jars. Looks like `javadoc.jar` is neither a subset or a superset of the other jars: it contains just the HTML files, and no source/compiled code. – Kevin Maxwell Jan 25 '19 at 19:21
  • @Andreas Thanks for the link. While that post explains sources JAR, it fails to explain the difference between: sources JAR, javadoc JAR, and just JAR. – Kevin Maxwell Jan 25 '19 at 19:22
  • @KevinMaxwell Correct, the `xxx-javadoc.jar` file contain just the **javadoc** files. Same as the `-sources.jar` file contain just the **source** files. And the plain `.jar` file contains the standard stuff, i.e. the compiled class files (and resource and meta-data files). – Andreas Jan 25 '19 at 19:28

1 Answers1

7

Does this mean that, given the sources.jar, I can generate the jar myself?

Yes, you could extract the Java code from the sources.jar using the jar command.

E.g. jar xf gson-2.8.5-sources.jar

And than compiling the Java files using javac.

But you need to have all the referenced dependencies in your classpath which are required when you call javac. These dependencies can be found in the project pom.xml

What is the general relationship between these three jars?

The .jar file contains the compliled code which is contained in the sources.jar. So using the sources.jar you could create the .jar yourself (as mentioned having the required dependencies). The javadoc.jar contains a static html site which content is extracted from all the javadocs which are present in the Java source files.

brass monkey
  • 5,841
  • 10
  • 36
  • 61