jar 配置及其内容
下载 Google Guice 时,我注意到其下载页面<上提供了两种主要“类型”的工件< /a>:
guice-3.0.zip
;和guice-3.0-src.zip
下载它们并检查其内容后,它们似乎是 Guice 3.0 版本的两个完全不同的“视角”。
guice-3.0.zip
仅包含 Guice jar 及其依赖项。然而,guice-3.0-src.zip
并不包含实际的 Guice jar,但它确实包含各种其他优点:javadocs、示例等
。这让我想到:在 Java 项目中发布的 jar 包必须有不同的“配置”。将这个想法与我从 Ivy(具有工件配置的概念)和 Maven(具有工件范围的概念)等构建工具中所知甚少的知识相结合,我发现想知道工件配置/范围和最终可交付成果(jar)之间的关系是什么。
假设我正在制作一个名为 my-utils.jar
的实用程序 jar。在它的 Ivy 描述符中,我可以引用 log4j 作为编译时依赖项,并将 junit 作为测试依赖项。然后我可以指定在构建时解析这两个“配置”中的哪一个。
我想知道的是:这些配置和最终结果中生成的 jar 内容之间的“映射”是什么?
例如,我可能会将所有 compile
配置依赖项打包到主 my-utils.jar
中,但是是否有理由打包我的 测试
依赖项到 my-utils-test.jar
中? my-utils-src.jar
中会包含什么样的依赖项?
我知道这些都是很多小问题,所以我想您可以将所有内容总结如下:
- 对于一个大型项目,发布的典型 jar 类型是什么(例如
guice-3.0.zip vs
guice-3.0-src.zip
等),每个的典型内容是什么,它们如何映射回 Ivy 配置或 Maven 范围的概念?
While downloading Google Guice I noticed two main "types" of artifacts available on their downloads page:
guice-3.0.zip
; andguice-3.0-src.zip
Upon downloading them both and inspecting their contents, they seem to be two totally different "perspectives" of the Guice 3.0 release.
The guice-3.0.zip
just contains the Guice jar and its dependencies. The guice-3.0-src.zip
, however, did not contain the actual Guice jar, but it did contain all sorts of other goodness: javadocs, examples, etc.
So it got me thinking: there must be different "configurations" of jars that get released inside Java projects. Crossing this idea with what little I know from build tools like Ivy (which has the concept of artifact configurations) and Maven (which has the concept of artifact scopes), I am wondering what the relation is between artifact configuration/scope and the end deliverable (the jar).
Let's say I was making a utility jar called my-utils.jar
. In its Ivy descriptor, I could cite log4j as a compile-time dependency, and junit as a test dependency. I could then specify which of these two "configurations" to resolve against at buildtime.
What I want to know is: what is the "mapping" between these configurations and the content of the jars that are produced in the end result?
For instance, I might package all of my compile
configuration dependencies wind up in the main my-utils.jar
, but would there ever be a reason to package my test
dependencies into a my-utils-test.jar
? And what kind of dependencies would go in the my-utils-src.jar
?
I know these are a lot of tiny questions, so I guess you can sum everything up as follows:
- For a major project, what are the typical varieties of jars that get released (such as
guice-3.0.zip
vsguice-3.0-src.zip
, etc.), what are the typical contents of each, and how do they map back to the concept of Ivy configurations or Maven scopes?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要运行的是
guice-3.0.zip
。它具有正确的包结构中的.class
文件。另一个 JAR,
guice-3.0-src.zip
,包含.java
源文件和其他您可能觉得有用的东西。智能 IDE(例如 IntelliJ)可以使用源 JAR 来允许您使用调试器单步进入 Guice 代码并查看发生了什么。你还可以通过阅读 Guice 源代码学到很多东西。了解比你我聪明的开发人员如何编写代码会有所帮助。
我想说,我发现的最好的例子是 Efficient Java Matrix Library 在 Google 代码中。它有一个广泛的 JUnit 测试套件,可以与源代码、文档以及您需要的其他所有内容一起使用。我认为这是最令人印象深刻的。我想自己效仿一下。
The one you need to run is
guice-3.0.zip
. It has the.class
files in the correct package structure.The other JAR,
guice-3.0-src.zip
, has the.java
source files and other things that you might find useful. A smart IDE, like IntelliJ, can use the source JAR to allow you to step into the Guice code with a debugger and see what's going on.You can also learn a lot by reading the Guice source code. It helps to see how developers who are smarter than you and me write code.
I'd say that the best example I've found is the Efficient Java Matrix Library at Google Code. That has an extensive JUnit test suite that's available along with the source, the docs, and everything else that you need. I think it's most impressive. I'd like to emulate it myself.