将 API 代码与类一起放入 JAR 中是否有任何缺点?
在 Java 中,如果将源代码 (.java) 文件与类 (.class) 一起打包到 jar 中,大多数 IDE(例如 Eclipse)将显示用于代码完成的 javadoc 注释。
IIRC 很少有开源项目能像 JMock 那样做到这一点。
可以说,我已经将 API 代码与实现代码完全分离,这样我就有了 myproject-api.jar 和 myproject-impl.jar 之类的东西,我有什么理由不应该将源代码放入 myproject-api.jar 中?
因为性能?尺寸?
为什么其他项目不这样做?
编辑:除了 Maven 下载问题之外,将我的源代码放入类 jar 中以支持尽可能多的开发人员(无论是否为 Maven)是否会造成任何伤害?
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 completion.
IIRC there are few open-source projects that do this like JMock.
Lets say I have cleanly separated my API code from implementation code so that I have something like myproject-api.jar and myproject-impl.jar is there any reason why I should not put the source code in my myproject-api.jar ?
Because of Performance? Size?
Why don't other projects do this?
EDIT: Other than the Maven download problem will it hurt anything to put my sources into the classes jar to support as many developers as possible (maven or not)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通常是由于分发原因:
如果您保留单独的二进制文件和源代码,则只能下载您需要的内容。
例如:
myproject-api.jar
和myproject-impl.jar
myproject-api-src.jar
和myproject-impl- src.jar
myproject-api-docs.zip
和myproject-impl-docs.zip
现在,m2eclipse - Maven for Eclipse 可以 自动下载源
现在,它还可以 生成正确的pom当任何人声明对您的 jar 的依赖项时,防止分发源或 javadoc jar。
OP评论:
好吧,实际上它(即“大小”)是一个问题。
Maven 已经患有“第一次构建时下载一半互联网”综合症。
如果还下载源代码和/或 javadocs,那就真的很烦人了。
另外,“分发”方面包括部署:在 webapp 服务器,部署一个包含源代码的 jar 并没有真正的优势。
最后,如果您确实需要将源代码与二进制文件关联起来,那么SO关于 Maven 的问题可能会有所帮助。
Generally because of distribution reason:
if you keep separate binaries and sources, you can download only what you need.
For instance:
myproject-api.jar
andmyproject-impl.jar
myproject-api-src.jar
andmyproject-impl-src.jar
myproject-api-docs.zip
andmyproject-impl-docs.zip
Now, m2eclipse - Maven for Eclipse can download sources automatically as well
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:
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.
使用 Maven,自动附加源,如下所示:
http://maven。 apache.org/plugins/maven-source-plugin/usage.html
和 javadoc 像这样:
http://maven.apache.org/plugins/maven-javadoc-plugin/jar-mojo.html
拾取
这样它们就会自动被 m2eclipse
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
or by m2eclipse