将API代码与类一起放入JAR有什么缺点吗? [英] Is there any disadvantage to putting API code into a JAR along with the classes?

查看:168
本文介绍了将API代码与类一起放入JAR有什么缺点吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Java中,如果将源代码(.java)文件与类( .class)一起打包到jar中,大多数IDE就像eclipse将显示代码完成的javadoc注释。

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几乎没有像JMock这样的开源项目。

IIRC there are few open-source projects that do this like JMock.

说我已经将我的API代码实现代码,所以我有一些像myproject-api.jar和myproject-impl.jar有什么原因我不应该把源代码放在我的myproject-api.jar中?

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 ?

由于性能?大小?

为什么其他项目不这样做?

Why don't other projects do this?

编辑:除了Maven下载问题会不会让我的资源进入类jar来支持尽可能多的开发人员(maven或不是)?

推荐答案

通常由于分发原因:

如果您保留单独的二进制文件和来源,您只能下载所需的内容。

例如:

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


  • myproject-api.jar myproject-impl.jar

  • myproject-api-src.jar myproject-impl-src.jar

  • myproject-api-docs.zip myproject-impl-docs.zip

  • 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

现在, m2eclipse - Maven for Eclipse 可以下载源以及

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

现在,它也可以,以防止在任何人声明对您的jar的依赖的源或javadoc jar的分发。

OP评论:

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:


也无法想象下载大小是一个问题(我的意思是2010年几十千万不应该是一个问题)。

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

实际上(即大小)是一个问题。

Maven已经从下载一半的互联网第一次建立综合征。

如果下载还有/ em>源和/或javadocs,这开始是非常令人讨厌的。

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.

另外,分配方面包括部署:在 webapp服务器,在其中部署具有源的jar没有真正的优势

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

最后,如果真的需要关联源使用二进制文件,这个 Maven上的SO问题可以帮助

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

这篇关于将API代码与类一起放入JAR有什么缺点吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆