Is there any disadvantage to putting API code into a JAR along with the classes?

前端 未结 2 1722
半阙折子戏
半阙折子戏 2020-12-16 23:26

In Java if you package the source code (.java) files into the jar along with classes (.class) most IDE\'s like eclipse will show the javadoc comments for code compl

相关标签:
2条回答
  • 2020-12-16 23:51

    Generally because of distribution reason:

    if you keep separate binaries and sources, you can download only what you need.
    For instance:

    • myproject-api.jar and myproject-impl.jar
    • myproject-api-src.jar and myproject-impl-src.jar
    • myproject-api-docs.zip and myproject-impl-docs.zip

    Now, m2eclipse - Maven for Eclipse can download sources automatically as well

    mvn eclipse:eclipse -DdownloadSources=true -DdownloadJavadocs=true 
    

    Now, it can also generate the right pom to prevent distribution of the source or javadoc jar when anyone declare a dependency on your jar.
    The OP comments:

    also can't imagine download size being an issue (i mean it is 2010 a couple 100k should not be a problem).

    Well actually it (i.e. "the size) is a problem.
    Maven suffers already from the "downloading half the internet on first build" syndrome.
    If that downloads also sources and/or javadocs, that begins to be really tiresome.

    Plus, the "distribution" aspect includes the deployment: in a webapp server, there is no real advantage to deploy a jar with sources in it.

    Finally, if you really need to associate sources with binaries, this SO question on Maven could help.

    0 讨论(0)
  • 2020-12-16 23:58

    Using maven, attach the sources automatically like this:

    http://maven.apache.org/plugins/maven-source-plugin/usage.html

    and the javadocs like this:

    http://maven.apache.org/plugins/maven-javadoc-plugin/jar-mojo.html

    That way they will automatically be picked up by

    mvn eclipse:eclipse -DdownloadSources=true -DdownloadJavadocs=true 
    

    or by m2eclipse

    0 讨论(0)
提交回复
热议问题