有人知道是否可以在Maven存储库中找到源jar吗?
当前回答
如果一个项目创建了一个项目源代码的jar,并将其部署到maven存储库中,那么你会发现它:)
仅供参考,源构件通常是由maven-source-plugin创建的。这个插件可以将项目的主要或测试源绑定到jar存档中,如配置源插件中所述:
(…)生成的jar文件将由finalName的值加上“-sources”(如果它是主要源代码)来命名。否则,它将是finalName加上“-test-sources”(如果它是测试源)。
附加的文本用来描述一个工件(这里是“-sources”或“-test-sources”)称为分类器。
要声明对使用分类器的工件的依赖,只需添加<classifier>元素。例如:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate</artifactId>
<version>3.2.7.ga</version>
<classifier>sources</classifier>
</dependency>
注意,您通常不会这样做,大多数ide都支持从主工件下载源(和/或JavaDoc),而无需显式地声明对它们的依赖。
最后,还要注意一些存储库搜索引擎允许使用分类器搜索工件(至少Nexus支持高级搜索)。请看这个搜索的例子。
其他回答
在Eclipse中
右键单击pom.xml 选择Run As -> Maven generate-sources 默认情况下,它将在.m2文件夹中生成源代码
Pre-Requisite:
Maven应该使用Eclipse进行配置。
Maven Micro-Tip: Get sources and Javadocs When you're using Maven in an IDE you often find the need for your IDE to resolve source code and Javadocs for your library dependencies. There's an easy way to accomplish that goal. mvn dependency:sources mvn dependency:resolve -Dclassifier=javadoc The first command will attempt to download source code for each of the dependencies in your pom file. The second command will attempt to download the Javadocs. Maven is at the mercy of the library packagers here. So some of them won't have source code packaged and many of them won't have Javadocs. In case you have a lot of dependencies it might also be a good idea to use inclusions/exclusions to get specific artifacts, the following command will for example only download the sources for the dependency with a specific artifactId: mvn dependency:sources -DincludeArtifactIds=guava
来源:http://tedwise.com/2010/01/27/maven-micro-tip-get-sources-and-javadocs/
文档:https://maven.apache.org/plugins/maven-dependency-plugin/sources-mojo.html
根据在Eclipse (Kepler)中查看Maven控制台,如果您试图在编辑器中从上述Maven依赖项打开一个类,而您还没有下载Maven依赖项的源代码,则将自动下载Maven依赖项的源代码。当您不想为所有依赖项获取源代码,但又不知道需要哪些依赖项时(而且您正在使用Eclipse),这是非常方便的。
我最终使用了@GabrielRamierez的方法,但接下来将使用@PascalThivent的方法。
如果您想手动找到任何工件的源jar文件,请转到特定工件的maven存储库位置,并在Files中单击“view All”。你可以找到源jar文件。
如果您正在使用Eclipse,我建议同时下载源代码和第三方库的Javadocs。
右键点击项目和下载两个截图如下。
下载Javadocs意味着通常可以从第三方库中获得方法的上下文帮助,其中包含有用的参数描述等。如果你不太了解图书馆,这是很重要的。在某些情况下,我发现当源代码不可用时,Javadocs是可用的。
推荐文章
- 将JSON字符串转换为HashMap
- web - inf在Java EE web应用程序中用于什么?
- Java 8: Lambda-Streams,过滤方法与异常
- 将JsonNode转换为POJO
- 如何查看IntelliJ中的编译错误列表?
- Java SimpleDateFormat("yyyy-MM-dd' t ' hh:mm:ss' z '")给出的时区为IST
- 杰克逊克服下划线,支持骆驼案
- List、List<?>, List<T>, List<E>, List<Object>
- 在Java中转换字符串到日历对象
- Maven检查存储库中更新的依赖项
- 在java中使用wait()和notify()的简单场景
- 增强的for循环中的Null检查
- c# vs Java Enum(适合c#新手)
- 如何在不强制转换的情况下将double转换为long ?
- for循环和for-each循环在性能上有区别吗?